Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Weird behavior of <jsp:forward>  RSS feed

 
Abhi Don
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello All,

From all the places that I could gather information about <jsp:forward> and getRequestDispatcher("").forward(), it says these are equal. Meaning, <jsp:forward> is just a tag format of getRequestDispatcher("").forward().

If I use:

<%request.getRequestDispatcher("Second.jsp").forward(request,response);%>
<%System.out.println("Request Forwarded");%>

I get the message saying "Request Forwarded" in the log. i.e. the execution does come back to the current page after processing the forward request.

While, if I use

<jsp:forward page="Second.jsp"/>
<%System.out.println("Request Forwarded");%>

I don’t see message in the log. i.e. once the request is forwarded, the execution doesn’t come back to the current page.

Please help me to clear my doubt.

 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66141
141
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you looked at the Java code generated for the JSP?
 
Abhi Don
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, I have and here is the difference.


when I use <jsp:forward> the generated servlet contains

if (true) {
_jspx_page_context.forward("/Second.jsp");
return;
}


and at the time of using getRequestDispatcher("").forward(), I get the below code in the generated servlet.

request.getRequestDispatcher("Second.jsp").forward(request,response);.

I am able to get the difference from the generated code, but my question is that, if this is the case then why do people say these are equal.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66141
141
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just because people say something, doesn't make it true.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!