• 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
 
Happiness is not a goal ... it's a by-product of a life well lived - Eleanor Roosevelt. Tiny ad:
the new thread boost feature brings a LOT of attention to your favorite threads
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!