Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

jsp:forward

 
bobby chaurasia
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can somebody explain why file1 will be displayed instead of jsp2

If the code below is executed in file1.jsp what will the location bar of the browser display after the execution.
<jsp:forward page="file2.jsp" />
You answered: A

A file1.jsp
B file2.jsp
C file1.jsp_file2.jsp
D Code will not compile
file1.jsp is displayed. A is true. B would be true when using response.sendRedirect
 
Carl Trusiak
Sheriff
Posts: 3341
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is displayed in a browsers Address or Location Bar is the URL requested from the server. Using jsp:forward, the clients single request is past along to the second resource without telling the browser so, the initial url is displayed. On response.sendRedirect, the clients initial rquest is anwsered with the http header set with the Redirect Response code causing the browser to make a new request for the second URL.
 
James Zhai
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So,RequestDispatcher.forward() is transparent to the browser, unlike
HttpServletResponse.sendRedirect
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic