Abhishek Jain Abhishek Jain - 6 months ago 26
Java Question

Why am I getting parameter value as null?

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


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


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

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);

you will see the value.