1,105,328 Community Members

How to redirect a page in JSP

Member Avatar
rpjanaka
Junior Poster in Training
69 posts since Sep 2006
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

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...

Member Avatar
peter_budo
Code tags enforcer
7,935 posts since Dec 2004
Reputation Points: 2,502 [?]
Q&As Helped to Solve: 1,028 [?]
Skill Endorsements: 66 [?]
Moderator
Featured
 
0
 

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...

Member Avatar
nikkiH
Junior Poster in Training
79 posts since Dec 2006
Reputation Points: 2 [?]
Q&As Helped to Solve: 4 [?]
Skill Endorsements: 0 [?]
 
0
 
Member Avatar
jwenting
duckman
8,359 posts since Nov 2004
Reputation Points: 1,399 [?]
Q&As Helped to Solve: 447 [?]
Skill Endorsements: 35 [?]
Infraction Points: 5
Team Colleague
 
0
 

NEVER use JSP scriptlets. They are the single worst part of the system and should never have been introduced.

Member Avatar
nikkiH
Junior Poster in Training
79 posts since Dec 2006
Reputation Points: 2 [?]
Q&As Helped to Solve: 4 [?]
Skill Endorsements: 0 [?]
 
0
 

Please share the non-scriplet way for us uneducated folks.

Member Avatar
rpjanaka
Junior Poster in Training
69 posts since Sep 2006
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

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

Member Avatar
peter_budo
Code tags enforcer
7,935 posts since Dec 2004
Reputation Points: 2,502 [?]
Q&As Helped to Solve: 1,028 [?]
Skill Endorsements: 66 [?]
Moderator
Featured
 
0
 

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

Member Avatar
jwenting
duckman
8,359 posts since Nov 2004
Reputation Points: 1,399 [?]
Q&As Helped to Solve: 447 [?]
Skill Endorsements: 35 [?]
Infraction Points: 5
Team Colleague
 
0
 

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.

Member Avatar
nikkiH
Junior Poster in Training
79 posts since Dec 2006
Reputation Points: 2 [?]
Q&As Helped to Solve: 4 [?]
Skill Endorsements: 0 [?]
 
-1
 

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. :D
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.

Member Avatar
jwenting
duckman
8,359 posts since Nov 2004
Reputation Points: 1,399 [?]
Q&As Helped to Solve: 447 [?]
Skill Endorsements: 35 [?]
Infraction Points: 5
Team Colleague
 
0
 

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.

Member Avatar
shobana_soma
Newbie Poster
2 posts since Nov 2009
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

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. :D
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.

_______________________________________________________ Reply from shobana
----------------------------------------------------------------------------------
Your code helped me a lot..
Thank you

Member Avatar
Thirusha
Posting Whiz
355 posts since Mar 2008
Reputation Points: 20 [?]
Q&As Helped to Solve: 58 [?]
Skill Endorsements: 2 [?]
 
0
 
<c:redirect url="http:www.someurl.com" />
sowmyameena
Newbie Poster
1 post since Jun 2012
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
Unverified Member
 
0
 

is goto statement available in jsp?

Member Avatar
javaAddict
Nearly a Senior Poster
3,274 posts since Dec 2007
Reputation Points: 900 [?]
Q&As Helped to Solve: 448 [?]
Skill Endorsements: 8 [?]
Team Colleague
Featured
 
0
 

Don't use GOTO in jsps. Start a new thread where you explain what you are trying to achieve

Member Avatar
Ice515
Newbie Poster
1 post since Jul 2012
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

<%pageContext.forward("page1.jsp");%>
Hope this Helps :)

You
This article has been dead for over three months: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article