This week's book giveaway is in the Other Languages forum.
We're giving away four copies of Functional Reactive Programming and have Stephen Blackheath and Anthony Jones on-line!
See this thread for details.
Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

jsp page redirection

 
suri jagadish
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 99
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try using the RequestDispatcher to forward the request, in stead of sending the browser a redirect:

 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
suri jagadish
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1026
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Ramesh Shanmugam
Ranch Hand
Posts: 132
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Vishnu Prakash
Ranch Hand
Posts: 1026
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic