• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

jsp page redirection

 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 99
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Try using the RequestDispatcher to forward the request, in stead of sending the browser a redirect:

 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 1026
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Ranch Hand
Posts: 132
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
He's my best friend. Not yours. Mine. You can have this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic