简体   繁体   中英

Why am I getting parameter value as null?

I hooked login.jsp and wrote following code in it:-

    <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. But when I am printing that value as in above code,it is printing null. I need that value as I want to store the same into session.Please help, any help would be appreciated.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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