0

I've found that when changing an included file, if I use the include action tag, then the change is reflected in the including jsp. But if I use the include directive, then the the change is not reflected in the including jsp.

However, I've found that the change does get reflected in the including jsp whether we use include action tag or include directive.

Please show me the difference using a program.

almcd
  • 1,069
  • 2
  • 16
  • 29
kushagra
  • 57
  • 2
  • 11
  • Related: [What's the difference between including files with JSP include directive, JSP include action and using JSP Tag Files?](https://stackoverflow.com/questions/14580120/whats-the-difference-between-including-files-with-jsp-include-directive-jsp-in/) – informatik01 Apr 10 '20 at 15:07

1 Answers1

0

The contents of the directives form part of the main JSP during the translation phase, ie., when the JSP is compiled in to an equivalent servlet. So the contents from the jsp included using a directive componnet are merged in to the parent jsp at the translation time which happens only once. This include directive was mainly meant to be used for addressing the headers and footers which are mostly static that doesn't get changed often.

The include action tag on the other hand is for including dynamic contents ie., you can choose to send a parameter to the tag which that tag may process and display. this is unlike the headers and footers showing the same content again and again.

Main.jsp

<jsp:include page="included.jsp"> 
    <jsp:param name="message" value="World" /> 
</jsp:include>

Included.jsp

<html>
<head>
</head>
<body>
<h2>Hello <%=request.getParameter("message") %></h2>
</body>
</html>

Also what server are you using. Since Tomcat7, things have changed and the main jsp will also compile if the included jsp(by any mechanism) is changed. this link has more details.

user3138997
  • 230
  • 1
  • 10