How to redirect a page in JSP

Reply

Join Date: Sep 2006
Posts: 68
Reputation: rpjanaka is an unknown quantity at this point 
Solved Threads: 0
rpjanaka rpjanaka is offline Offline
Junior Poster in Training

How to redirect a page in JSP

 
0
  #1
Feb 14th, 2007
hi all.

I have a form in page1.jsp. the action for that form submit is in page2.jsp

so I want to just come back to the page1.jsp after processing the request.(reload the first page again)

so in page2.jsp, how can i redirect the display page to the page1.jsp


here I tried to used the "<jsp:forward page=" tag
but my request is not to forward only the request object
I wanna redirect the page

thanks...
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 4,212
Reputation: peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of 
Solved Threads: 489
Moderator
Featured Poster
peter_budo's Avatar
peter_budo peter_budo is offline Offline
Code tags enforcer

Re: How to redirect a page in JSP

 
0
  #2
Feb 14th, 2007
instead of JSP use servlet, so from page1.jsp send form to servlet where you validate and process the form and after that you can get back to page1.jsp
Question is why do you want to go back? It is because of error which is OK, or some other reason which is unclear to me...
Learn to see in another's calamity the ills which you should avoid.
Publilius Syrus
(~100 BC)

LJC - London Java Community, Graduate & Undergraduate Software Development Community, JAVAWUG (Java Web User Group), The London Android Group
Reply With Quote Quick reply to this message  
Join Date: Dec 2006
Posts: 79
Reputation: nikkiH is an unknown quantity at this point 
Solved Threads: 4
nikkiH's Avatar
nikkiH nikkiH is offline Offline
Junior Poster in Training

Re: How to redirect a page in JSP

 
0
  #3
Feb 14th, 2007
Last edited by nikkiH; Feb 14th, 2007 at 12:20 pm.
Google is your friend. I'm giving examples, not typing up your whole app for you. You run code at your own risk.
Bored? Visit http://www.kaelisspace.com/
Reply With Quote Quick reply to this message  
Join Date: Nov 2004
Posts: 6,143
Reputation: jwenting is just really nice jwenting is just really nice jwenting is just really nice jwenting is just really nice 
Solved Threads: 212
Team Colleague
jwenting's Avatar
jwenting jwenting is offline Offline
duckman

Re: How to redirect a page in JSP

 
0
  #4
Feb 14th, 2007
NEVER use JSP scriptlets. They are the single worst part of the system and should never have been introduced.
As people are clearly allowed to attack me but I'm not allowed to defend myself, I no longer post to this site.
Reply With Quote Quick reply to this message  
Join Date: Dec 2006
Posts: 79
Reputation: nikkiH is an unknown quantity at this point 
Solved Threads: 4
nikkiH's Avatar
nikkiH nikkiH is offline Offline
Junior Poster in Training

Re: How to redirect a page in JSP

 
0
  #5
Feb 14th, 2007
Please share the non-scriplet way for us uneducated folks.
Google is your friend. I'm giving examples, not typing up your whole app for you. You run code at your own risk.
Bored? Visit http://www.kaelisspace.com/
Reply With Quote Quick reply to this message  
Join Date: Sep 2006
Posts: 68
Reputation: rpjanaka is an unknown quantity at this point 
Solved Threads: 0
rpjanaka rpjanaka is offline Offline
Junior Poster in Training

Re: How to redirect a page in JSP

 
0
  #6
Feb 14th, 2007
here i wanna add some data to the database and show the first page again to add another data.

so the request processing task is done in the page2.jsp . the form is included in page1.jsp
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 4,212
Reputation: peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of 
Solved Threads: 489
Moderator
Featured Poster
peter_budo's Avatar
peter_budo peter_budo is offline Offline
Code tags enforcer

Re: How to redirect a page in JSP

 
0
  #7
Feb 15th, 2007
Originally Posted by rpjanaka View Post
here i wanna add some data to the database and show the first page again to add another data.
so the request processing task is done in the page2.jsp . the form is included in page1.jsp
OK thas fine if you want to go back to page1 for more data, but you shoudn't connect to database and process request in JSP, you should do it in servlet. That is what servlets are build for
Learn to see in another's calamity the ills which you should avoid.
Publilius Syrus
(~100 BC)

LJC - London Java Community, Graduate & Undergraduate Software Development Community, JAVAWUG (Java Web User Group), The London Android Group
Reply With Quote Quick reply to this message  
Join Date: Nov 2004
Posts: 6,143
Reputation: jwenting is just really nice jwenting is just really nice jwenting is just really nice jwenting is just really nice 
Solved Threads: 212
Team Colleague
jwenting's Avatar
jwenting jwenting is offline Offline
duckman

Re: How to redirect a page in JSP

 
0
  #8
Feb 15th, 2007
Originally Posted by nikkiH View Post
Please share the non-scriplet way for us uneducated folks.
Any decent book about JSP will teach you to use JSTL and/or JSF instead of scriptlets.

Of course many books you get cheap or find pirated online are old ones from before JSTL even existed, or written by people who don't care about teaching things properly but only want to get rich quick selling books to schools.
As people are clearly allowed to attack me but I'm not allowed to defend myself, I no longer post to this site.
Reply With Quote Quick reply to this message  
Join Date: Dec 2006
Posts: 79
Reputation: nikkiH is an unknown quantity at this point 
Solved Threads: 4
nikkiH's Avatar
nikkiH nikkiH is offline Offline
Junior Poster in Training

Re: How to redirect a page in JSP

 
-1
  #9
Feb 15th, 2007
That's great, but since you're trying to teach us how NOT to use scriptlets, I'd love to know the right way to do this.

<%
response.sendRedirect("someUrl");
%>

Please share.
I'm much more a C# person than Java these days and the Java I did do was on an old crappy server that didn't fully support JSTL, so I have no idea how else you would do this. This is what Sun had on its site. Please tell me the better way to do this so I know for future reference.
Last edited by nikkiH; Feb 15th, 2007 at 4:34 pm.
Google is your friend. I'm giving examples, not typing up your whole app for you. You run code at your own risk.
Bored? Visit http://www.kaelisspace.com/
Reply With Quote Quick reply to this message  
Join Date: Nov 2004
Posts: 6,143
Reputation: jwenting is just really nice jwenting is just really nice jwenting is just really nice jwenting is just really nice 
Solved Threads: 212
Team Colleague
jwenting's Avatar
jwenting jwenting is offline Offline
duckman

Re: How to redirect a page in JSP

 
0
  #10
Feb 16th, 2007
Do NOT do that in a JSP, use a servlet...
How hard can it get.

JSP are for PRESENTATION only, NEVER for application flow control or business logic.
As people are clearly allowed to attack me but I'm not allowed to defend myself, I no longer post to this site.
Reply With Quote Quick reply to this message  
Reply

Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC