jsp頁面提交按鈕onclick函數在javascript中。當我第一次點擊按鈕沒有重定向到CallService.jsp。我只點擊了按鈕兩到三次後,只有該頁面將被重定向。Window.location.href有時候不工作的原因是什麼?
請給我的解決方案或原因
我的代碼
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<script type="text/javascript">
function sample()
{
var uname = document.getElementById("uname").value;
//var pwd = document.getElementById("pwd").value;
window.location.href("CallService.jsp?username="+uname);
}
</script>
<body>
<h3>User Login</h3> <br>
<form name="userlogin" method="post">
User Name : <input type="text" name="uname" id="uname"> <br>
Password : <input type="text" name="pwd" id="pwd"> <br>
<input type="submit" value="Submit" onclick="sample(this);" >
<input type="reset" value="Cancel">
<div id="name"></div>
<div id="email"></div>
</form>
</body>
</html>
CallService.jsp
<%
String uname = request.getParameter("username");
//String pwd = request.getParameter("password");
out.println(uname);
%>
您在提交表格,並重定向到另一種形式同時進行。這是不正確的 – karaxuna