Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How To "Forward Request" in JSP

 
JiaPei Jen
Ranch Hand
Posts: 1309
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How do we forward request to anther JavaServer Page (filename.jsp)?
For example, we can write the following in Servlet:
if (request.getParameter("flights") != null) {
gotoPage("BookFlights.jsp", request, response);
private void gotoPage(String address,
HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {
RequestDispatcher dispatcher =
getServletContext().getRequestDispatcher(address);
dispatcher.forward(request, response);
}
If we have to write the above code fragment in JSP, how are we supposed to write the code? Thank you if you could show it to me.
 
Thomas Paul
mister krabs
Ranch Hand
Posts: 13974
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
<% response.sendRedirect(String); %>
 
Raghav Mathur
Ranch Hand
Posts: 641
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
one way to send your request through redirection is what thomas has given you and the second way is :---
<jsp: forward page= "path of the file" />
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic