javascript中提交按钮onclick功能的jsp页面。当我第一次单击按钮时未重定向到 CallService.jsp。之后,我点击按钮两到三遍,只有那个页面会被重定向。
请给我解决方案或理由
我的代码
<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>
呼叫服务.jsp
<%
String uname = request.getParameter("username");
//String pwd = request.getParameter("password");
out.println(uname);
%>