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

时间:2016-09-14 06:36:54

标签: java liferay

我挂了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> 

我在otpText中输入了一些值,当我提交表单时,该值显示在url中。但是,当我按照上面的代码打印该值时,它将打印为null。我需要这个值,因为我想将它存储到session.Please帮助,任何帮助将不胜感激。

1 个答案:

答案 0 :(得分:0)

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.

相关问题