Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/455.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在表单中使用javascript确认框,我可以在其中使用jsp吗?_Javascript_Forms_Jsp - Fatal编程技术网

如何在表单中使用javascript确认框,我可以在其中使用jsp吗?

如何在表单中使用javascript确认框,我可以在其中使用jsp吗?,javascript,forms,jsp,Javascript,Forms,Jsp,我的JavaScript代码不起作用: <script type="text/javascript"> function verify() { var amount = document.getElementById("amount"); var commission = document.getElementById("commission"); var commissionPayed = parseFloat(amount

我的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);
    }

函数验证(){
var金额=document.getElementById(“金额”);
var佣金=document.getElementById(“佣金”);
var commissionPayed=parseFloat(金额)*parseFloat(佣金);
msg=“提取金额:“+Amount.value+”\n已支付佣金:“+commissionPayed.value;
//我们所要做的就是返回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的方法,例如
${object}

我可以用JSP进行整个计算吗

我可以用jsp进行整个计算吗。。。我会在服务器端做,是的。不应相信客户端的这种计算

要在jsp中获取值,可以使用标准标记:


如果你用谷歌搜索一下的话,这里有很多关于标签主题的教程。例如

。value
是每个表单元素的成员,而不是每个数值

function verify(){
    var amount = document.getElementById("amount").value;
    var commission = document.getElementById("commission").value;
    var commissionPayed = parseFloat(amount) * parseFloat(commission);
    msg = "Withdraw Amount: " + amount + "\n Commission payed: " + commissionPayed;
    //all we have to do is return the return value of the confirm() method
    return confirm(msg);
}
当然,出于安全原因,您需要在服务器上再次执行相同的计算——JavaScript计算仅适用于用户确认。存在Greasemonkey、篡改数据和Firebug等工具;您不能信任web浏览器为后端业务逻辑提供准确的计算

如果在HTML、CSS或JavaScript代码(特别是字符串值)中包含任何服务器端变量,则需要正确转义(使用适合所讨论的数据格式的函数),否则可能会发生(XSS)攻击。我链接到的页面包含易受攻击的JSP代码的示例片段


例如,JSP有一个名为的标记,用于执行HTML转义。但是,如果在JavaScript代码块(或样式属性)中依赖它,则脚本可能不安全。

是否在文本框和隐藏表单字段中都输入了有效的数字?顺便说一句,您可以使用。