如何在表单中使用JavaScript确认框,我可以在其中使用jsp吗?
|
我的JavaScript代码不起作用:
<script type=\"text/javascript\">
function verify() {
var amount = document.getElementById(\"amount\");
var commission = document.getElementById(\"commission\");
var commissionPayed = parseFloat(amount) * parseFloat(commission);
msg = \"Withdraw Amount: \" + amount.value + \"\\n Commission payed: \" + commissionPayed.value;
//all we have to do is return the return value of the confirm() method
return confirm(msg);
}
表格本身:
<form action=\"Controller\" method=\"post\" onSubmit=\"return verify()\">
<h1>Withdraw</h1>
<input type=\"hidden\" name=\"command\" id=\"command\" value=\"withdrawAction\">
<input type=\"hidden\" name=\"commission\" id=\"commission\" value=\"${commission}\">
<p>Amount: <input type=\"text\" name=\"amount\" id=\"amount\"/></p>
<input type=\"submit\" name=\"name\" value=\"Withdraw\" onclick=\"confirmation()\"/></p>
</form>
在消息中,我得到的佣金为未定义的值。我究竟做错了什么?
有没有办法在脚本中使用JSP,例如script2ѭ?
我可以在JSP中进行整个计算吗?
没有找到相关结果
已邀请:
2 个回复
芭隘的盘石
当然,出于安全原因,您需要在服务器上再次执行相同的计算-JavaScript计算仅适用于用户确认。存在诸如Greasemonkey,篡改数据和Firebug之类的工具。您将无法信任Web浏览器为后端业务逻辑提供准确的计算。 如果您在HTML,CSS或JavaScript代码中包含任何服务器端变量(尤其是字符串值),则需要对其进行正确的转义(使用适用于所讨论数据格式的函数,或者使用跨站点脚本(XSS) )攻击可能会发生,我链接到的页面包含易受攻击的JSP代码的示例片段。 例如,JSP有一个名为
蹄渭信妥扳
如果您也谷歌一些,有很多关于标签主题的教程。例如http://www.developer.com/java/ejb/article.php/1447551/An-Introduction-to-JSP-Standard-Template-Library-JSTL.htm