i have asked this question previously but the solution is not working .
the question is about rediretion form with in the jsp page.
<input type="hidden" name="source" value="test">
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
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.
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
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 ]
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.