aspose file tools*
The moose likes JSP and the fly likes jsp page redirection Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "jsp page redirection" Watch "jsp page redirection" New topic
Author

jsp page redirection

suri jagadish
Greenhorn

Joined: Sep 14, 2005
Posts: 19
hi all
i have asked this question previously but the solution is not working .
the question is about rediretion form with in the jsp page.

page1.jsp

<form action="page2.jsp">
<input type="hidden" name="source" value="test">
</form>

page2.jsp

<%
if(request.getParameter("source")==null))
{
response.sendRedirect("page1.jsp");
}
%>

after the form is submitted form the page1.jsp it comes to page2.jsp here after the page2.jsp is realised if we refresh the page the request parameter will be null and the page has to be redirected to the page1.jsp this scriplet is present in the page2.jsp this solution is not working .the functionality that i want is after coming to page2.jsp if we refresh the page it should be redirected to the page1.jsp

thanku
regards
jagadish
Scheepers de Bruin
Ranch Hand

Joined: Jul 19, 2005
Posts: 99
Try using the RequestDispatcher to forward the request, in stead of sending the browser a redirect:



We're doomed!!<br />Yay!!!<br />No that's bad Girr!!<br />Yay!!!
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Originally posted by suri jagadish:
this solution is not working .the functionality that i want is after coming to page2.jsp if we refresh the page it should be redirected to the page1.jsp


It's not working because clicking the refresh button will send the same form values that were contained in the first call to the page.


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
suri jagadish
Greenhorn

Joined: Sep 14, 2005
Posts: 19
hi all
the request dispatcher method does not work it gives an illegeal state exception .

coming to the first solution what yu have said is correct but the request is same as the request because of the first call but i want a solution for this redirection

please help this is very much necessary for my application

thanking u
regards
jagadish.suri
Vishnu Prakash
Ranch Hand

Joined: Nov 15, 2004
Posts: 1026
Suri I got the solution to your problem

Instead of transfering the control from the first jsp directly to second jsp use a controller servlet.

Code for first Jsp (JspOne.jsp)



Code for controller servlet



code for second jsp (JspTwo.jsp)




With this logic when you submit your first jsp page the control with go to controller servlet and from there will be redirected to second jsp page. Now you are in your second jsp page. When you make a refresh the control will go back to your first jsp page.

I had executed the code and everything is working perfectly for me. All the best.
[ December 07, 2005: Message edited by: Vishnu Prakash ]

Servlet Spec 2.4/ Jsp Spec 2.0/ JSTL Spec 1.1 - JSTL Tag Documentation
Ramesh Shanmugam
Ranch Hand

Joined: Sep 13, 2004
Posts: 132
you can give the response.sendRedirect() method outside the IF condition,
so eventhough the page is refreshed it will be redirected to the page1.jsp

Thanks,
Ramesh


Ramesh Shanmugam - SCJP 1.5
Vishnu Prakash
Ranch Hand

Joined: Nov 15, 2004
Posts: 1026

you can give the response.sendRedirect() method outside the IF condition,
so eventhough the page is refreshed it will be redirected to the page1.jsp


Think about this use case
What happens when the user enters for the first time?

When he presses the submit button he will be immediately taken back to the first page without displaying the second page. But the problem demands in the other way. Only when the second page is refreshed user should be taken back to first page.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: jsp page redirection