1

in how many way can we redirect to next jsp page from one page to another page apart from following two ways,

RequestDispatcher rd = request.getRequestDispatcher("MyPage.jsp");
rd.forward(request, response);

and

response.sendRedirect("MyPage.jsp");

when i go to second page(MyPage.jsp) it has to load as fresh page from server side,

hvgotcodes
  • 118,147
  • 33
  • 203
  • 236
Naresh
  • 245
  • 1
  • 7
  • 18

3 Answers3

2

RequestDispatcher and sendRedirect are different things. If you want to

load as fresh page from server side,

then RequestDispatcher won't work. The client (browser) still thinks the content comes from the original request.

Community
  • 1
  • 1
PeterMmm
  • 24,152
  • 13
  • 73
  • 111
0

Take from JGuru:

http://www.jguru.com/faq/view.jsp?EID=376&page=2

You can also physically alter the Location HTTP header attribute, as shown below:

<%
response.setStatus(HttpServletResponse.SC_MOVED_PERMANENTLY);
String newLocn = "/newpath/index.html";
response.setHeader("Location",newLocn);
%>
Jonathan Holloway
  • 62,090
  • 32
  • 125
  • 150
  • I'm not sure why this is accepted. If this is accepted because it's in essence a different way, then it's okay. But if this is accepted because it's to be used as a real solution, then this should rather be downvoted. Scriptlets in a JSP are poor practice. Using `response.sendRedirect()` in a servlet is the only feasible way to send a redirect. The `requestDispatcher.forward()` doesn't send a redirect at all so it is definitely not one of the ways. – BalusC Jan 21 '11 at 17:08
0

Redirect has two types permanent and temporary redirect.

Dead Programmer
  • 12,427
  • 23
  • 80
  • 112