0

In jsp we can use both jsp include tag and page directive include tag to include jsp classes in another jsp file.

<jsp:include page="sample.jsp" flush="false" />

<%@include file="./inc/jsp3.jsp" %>

To my knowledge the main difference is <jsp:include> the file is being included during request processing and <%@include file=""> included at jsp to servlet translation phase.

Althought while working in a real world projects I mostly see jsp include tags are in dynamic web pages loading inside of another jsp page and directive include tag in basic header footer attachment to the jsp pages.

What are the different practical scenarios that we should use these tags and why? Please give me a small explanation (with example if possible).


Thank you.

Dil.
  • 1,996
  • 7
  • 41
  • 68
  • ,you can pass a dynamic page name to .Once I use it in a jsp tag,so I pass what page I want to include to the tag.But include can not. – lin Apr 02 '18 at 12:26
  • @ChaojunZhong can you elaborate with an example please? – Dil. Apr 02 '18 at 12:30
  • Also you can put file name in your request, For example, if the login user is a manager, you can do like request.addAttribute("fileName","manager"), and include jsp file named "manager",, if he is a worker, you can include jsp file named "worker". – lin Apr 02 '18 at 12:32
  • @ChaojunZhong what is filename is? is that the file path? Then why we add it to request also? jsp:include is going taking to manager.jsp – Dil. Apr 02 '18 at 12:45
  • @JonathanLaliberte thanks that's quite helpful – Dil. Apr 02 '18 at 12:46

0 Answers0