简体   繁体   English

为什么我将参数值设置为null?

[英]Why am I getting parameter value as null?

I hooked login.jsp and wrote following code in it:- 我钩住login.jsp并在其中编写了以下代码:

    <script>

    function a(){
    var otp=document.getElementById("otpText").value;
    document.location.href="?otp="+otp;
    <% System.out.println(request.getParameter("otp")); %>    //printing null
    return false;
    }

    </script>

    <form name="otp" method="post" action="" >
    Enter otp:
    <input type="text" name="otpText" id="otpText"/>
    <input type="submit" value="Submit" onClick="return a()"/>
    </form> 

I typed some value inside otpText and that value is displayed in the url when I submitted the form. 我在otpText中键入了一些值,并且在提交表单时该值显示在url中。 But when I am printing that value as in above code,it is printing null. 但是当我按照上面的代码打印该值时,它打印的是null。 I need that value as I want to store the same into session.Please help, any help would be appreciated. 我需要该值,因为我想将其存储到session.Please帮助,任何帮助,将不胜感激。

If you change your code to 如果您将代码更改为

var otp=document.getElementById("otpText").value;
console.log (otp);  // or alert (otp);
document.location.href="?otp="+otp;

you will see the value. 您会看到价值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM