sendredirect not working as expected.
posted 20 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Please look at the code below. My intention is that when I click submit sendredirect should send me to another URL. But seems as soon as the form loads it send me to redirected URL.
Can someone sya what is wrong with this code?
----------------->
<html>
<head>
<script language="javascript">
function call_report() {
<% response.sendRedirect("http://localhost:9050/myapplication/xxx.jsp"); %>
return true;
}
<head>
</head>
<body >
<table>
<form name=repform method="post" onsubmit="return call_report()" >
<tr>
<td align="center"><input type="submit" style="font-weight: bold" name="Submit" value="Submit" ></td>
<td align="center"><input type="reset" name="Reset" style="font-weight: bold" value="Reset"></td>
</tr>
</form>
</table>
</body>
</html>
Can someone sya what is wrong with this code?
----------------->
<html>
<head>
<script language="javascript">
function call_report() {
<% response.sendRedirect("http://localhost:9050/myapplication/xxx.jsp"); %>
return true;
}
<head>
</head>
<body >
<table>
<form name=repform method="post" onsubmit="return call_report()" >
<tr>
<td align="center"><input type="submit" style="font-weight: bold" name="Submit" value="Submit" ></td>
<td align="center"><input type="reset" name="Reset" style="font-weight: bold" value="Reset"></td>
</tr>
</form>
</table>
</body>
</html>
posted 20 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Javascript functions get executed on the client side.
JSPs write the page (including the JS functions) on the server side.
As soon as the page is shown in the browser, all the JSP functionality is done.
In your case, the sendRedirect is being called as soon as it's seen (the first load).
You can either implement this in Javascript document.location.url = ".." or something like that.
OR
You can implement it on the server by testing to see if the the form has been submitted yet. If so, redirect. If not show the page.
In the top of your page:
JSPs write the page (including the JS functions) on the server side.
As soon as the page is shown in the browser, all the JSP functionality is done.
In your case, the sendRedirect is being called as soon as it's seen (the first load).
You can either implement this in Javascript document.location.url = ".." or something like that.
OR
You can implement it on the server by testing to see if the the form has been submitted yet. If so, redirect. If not show the page.
In the top of your page:
Raj Puri
Ranch Hand
Posts: 189
posted 20 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Thank you for clearing it so well. So any code in Javascript gets executed
irrespective of its event? Kind of little confusing for me as I was expecting code to be executed on that javascript event(onsubmit here). That definitely seems to be the case here.
irrespective of its event? Kind of little confusing for me as I was expecting code to be executed on that javascript event(onsubmit here). That definitely seems to be the case here.
posted 20 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
No, The Server side code is fired on the server and the client side code is fired on the client.
If you wanted to do it with JavaScript, you would have to use JavaScript not the server side code.
e.g.
Eric
If you wanted to do it with JavaScript, you would have to use JavaScript not the server side code.
e.g.
Eric
posted 20 years ago
No, think of it as the JSP getting fired first, on the server, before the Javascript interpreter ever sees it.
As far as the JSP engine is concerned your Javascript function is just text.
The first instruction that it saw (mixed in with the other text) was your sendRedirect.
Another way to think of it: Your JSP is writing your HTML and Javascript Code.
[ February 17, 2005: Message edited by: Ben Souther ]
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Originally posted by Raj Puri:
Thank you for clearing it so well. So any code in Javascript gets executed
irrespective of its event? Kind of little confusing for me as I was expecting code to be executed on that javascript event(onsubmit here). That definitely seems to be the case here.
No, think of it as the JSP getting fired first, on the server, before the Javascript interpreter ever sees it.
As far as the JSP engine is concerned your Javascript function is just text.
The first instruction that it saw (mixed in with the other text) was your sendRedirect.
Another way to think of it: Your JSP is writing your HTML and Javascript Code.
[ February 17, 2005: Message edited by: Ben Souther ]
posted 20 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
why don't u use the 'action' parameter from the form? it simply direct u to the page u specified in the action parameter.
<form name="form1" method="POST" action="the_page_u_wish.jsp">
<input type="submit" name="Submit" value="Submit">
<input type="reset" name="Reset" value="Reset">
</form>
<form name="form1" method="POST" action="the_page_u_wish.jsp">
<input type="submit" name="Submit" value="Submit">
<input type="reset" name="Reset" value="Reset">
</form>
posted 20 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
evan,
JavaRanch is a community of people from all over the world, many of who are not native English speakers. While using abbreviations like "u" instead of spelling out "you" is convenient when text messaging your friends on a cell phone or in a chat room, it presents an extra challenge to those that are already struggling with English. Additionally, such shortcuts may confound automated translation tools that patrons of the Ranch may be making use of.
I would like to ask for your help in making the content of JavaRanch a little easier to read for everybody that visits here by not using such abbreviations.
thanks,
bear
JSP Forum Bartender
JavaRanch is a community of people from all over the world, many of who are not native English speakers. While using abbreviations like "u" instead of spelling out "you" is convenient when text messaging your friends on a cell phone or in a chat room, it presents an extra challenge to those that are already struggling with English. Additionally, such shortcuts may confound automated translation tools that patrons of the Ranch may be making use of.
I would like to ask for your help in making the content of JavaRanch a little easier to read for everybody that visits here by not using such abbreviations.
thanks,
bear
JSP Forum Bartender
| If I had asked people what they wanted, they would have said faster horses - Ford. Tiny ad: Paul Wheaton's 16th Kickstarter: Gardening playing cards for gardeners and homesteaders https://coderanch.com/t/889615/Paul-Wheaton-Kickstarter-Gardening-playing |










