admin管理员组文章数量:1026925
jsp page for submit button onclick function in javascript. when i click button first time not redirected to CallService.jsp. I click the button two to three times after that only that page will be redirected.
Pls give me the solution or reason
My Code
<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);
%>
jsp page for submit button onclick function in javascript. when i click button first time not redirected to CallService.jsp. I click the button two to three times after that only that page will be redirected.
Pls give me the solution or reason
My Code
<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);
%>
Share
Improve this question
asked Oct 24, 2013 at 8:01
Jagathesewaren KuppurajJagathesewaren Kuppuraj
911 gold badge3 silver badges11 bronze badges
1
- 4 You are submitting form and redirecting to another form same time. It's not right – karaxuna Commented Oct 24, 2013 at 8:04
6 Answers
Reset to default 2Your button type is
<input type="submit" value="Submit" onclick="sample(this);" >
replace it with:
<input type="button" value="Submit" onclick="sample(this);" >
or
Call your function when submitting form like this:
<form method="post" name="fromname" onsubmit="yourfunction()">
Try this:
window.location.href = "CallService.jsp?username="+uname;
You are submitting form and redirecting to another form same time. It's not right
<input type="submit" value="Submit" onclick="sample(this);" >
You cannot submit and redirect this.
In your servlet / jsp where the form is submitted, redirect the page.
please try:
function sample()
{
var uname = document.getElementById("uname").value;
//var pwd = document.getElementById("pwd").value;
window.location.href("CallService.jsp?username="+uname);
//FUNCTION MUST RETURN FALSE!!
return false;
}
<input type="submit" value="Submit" onclick="return sample(this);" >
this way js function will need to be evaluted before making postback
Why dont you try redirecting from you java class, like this
actionResponse.sendRedirect("CallService.jsp");
Since you are fetching the data using javascript here :
var uname = document.getElementById("uname").value;
theres no need to use a 'submit' button. Try to change
<input type="submit" value="Submit" onclick="sample(this);" >
into
<input type="button" value="Submit" onclick="sample(this);" >
jsp page for submit button onclick function in javascript. when i click button first time not redirected to CallService.jsp. I click the button two to three times after that only that page will be redirected.
Pls give me the solution or reason
My Code
<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);
%>
jsp page for submit button onclick function in javascript. when i click button first time not redirected to CallService.jsp. I click the button two to three times after that only that page will be redirected.
Pls give me the solution or reason
My Code
<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);
%>
Share
Improve this question
asked Oct 24, 2013 at 8:01
Jagathesewaren KuppurajJagathesewaren Kuppuraj
911 gold badge3 silver badges11 bronze badges
1
- 4 You are submitting form and redirecting to another form same time. It's not right – karaxuna Commented Oct 24, 2013 at 8:04
6 Answers
Reset to default 2Your button type is
<input type="submit" value="Submit" onclick="sample(this);" >
replace it with:
<input type="button" value="Submit" onclick="sample(this);" >
or
Call your function when submitting form like this:
<form method="post" name="fromname" onsubmit="yourfunction()">
Try this:
window.location.href = "CallService.jsp?username="+uname;
You are submitting form and redirecting to another form same time. It's not right
<input type="submit" value="Submit" onclick="sample(this);" >
You cannot submit and redirect this.
In your servlet / jsp where the form is submitted, redirect the page.
please try:
function sample()
{
var uname = document.getElementById("uname").value;
//var pwd = document.getElementById("pwd").value;
window.location.href("CallService.jsp?username="+uname);
//FUNCTION MUST RETURN FALSE!!
return false;
}
<input type="submit" value="Submit" onclick="return sample(this);" >
this way js function will need to be evaluted before making postback
Why dont you try redirecting from you java class, like this
actionResponse.sendRedirect("CallService.jsp");
Since you are fetching the data using javascript here :
var uname = document.getElementById("uname").value;
theres no need to use a 'submit' button. Try to change
<input type="submit" value="Submit" onclick="sample(this);" >
into
<input type="button" value="Submit" onclick="sample(this);" >
本文标签: javawhat is the reason for Windowlocationhref not working sometimesStack Overflow
版权声明:本文标题:java - what is the reason for Window.location.href not working sometimes? - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745654101a2161493.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论