[英]Why am I getting parameter value as null?
我鈎住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幫助,任何幫助,將不勝感激。
如果您將代碼更改為
var otp=document.getElementById("otpText").value;
console.log (otp); // or alert (otp);
document.location.href="?otp="+otp;
您會看到價值。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.