Pass Control from one JSP page to another

Write Sample Code to pass control from one JSP page to another?

Questions by Aparna Rao

Showing Answers 1 - 4 of 4 Answers

There are 2 ways to redirect the page
1) Use the forward :- By using this
you will get the all the objects in the redirected page.
2) response.sendRedirect("Path") :- In This case the control is not transferred to the next page.

delindia

  • Jan 2nd, 2012
 

The RequestDispatcher objects forward method to pass the control.
The response.sendRedirect method

Code
  1. <%      response.sendRedirect("RedirectIfSuccessful.html""n""""/form.jsp""/welcome.jsp"

  Was this answer useful?  Yes

raman

  • Nov 12th, 2014
 

Hi,
you want to call it inside of server ?

then save your values to session and do include ( if you want to continue on top page ) or (redirection) forward - if you want to finish on called page

example 1. include :

Code
  1. span style="color: #ff0000;">"test";

  2.    session.setAttribute("some_name_here",obj);

  3.    pageContext.include("relative name of your page""some_name_here");

  4.     .... use variable



example 2. forward :
same like previous but replace pageContext.include by :

<%@ forward file="your page name" %>


for security issues is sometimes better to use ( if its possible )

response.sendRedirect(" some page ");
out.flush();
return;

but take care of output buffer ( to not get exception )

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions