• Post Reply Bookmark Topic Watch Topic
  • New Topic

diff between <jsp:include /> and request.getRequestDispatcher().include(req,res)

 
Harish Govind
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please anyone clarify me on the above things.
 
Bauke Scholtz
Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Both does the same. The one is to be used in a JSP file and the other is to be used in a Java (servlet) class.
You can´t use JSP tags in a Java (servlet) class and you should not use Java code in a JSP file.
 
Amit Ghorpade
Bartender
Posts: 2856
10
Fedora Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also consider reading this .
 
Satya Maheshwari
Ranch Hand
Posts: 368
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is some addition from my side:

1. <js:include ...> provides a flush attribute which is set to false by default. For requestDispatcher.include, you would need to explicitely call flushbuffer of servlet response

2. path attribute in jsp:include may not begin with '/'. It considers the path starting from application root by default. For requestDispatcher.include, if its got from ServletContext, you need to give a path starting with '/' i.e. the absolute path. Relative path can be given for requestDispatcher got from HttpRequest.
 
Bauke Scholtz
Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, but to end, they does both the same. The one is a taglib for use in JSP and the other is plain vanilla Java code for use in Java classes. That´s all.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!