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