Master java skills

jsp:include

jsp:include action tag is used to include the content of another resource. The another resource may be another jsp page, a html or a servlet.

The jsp include action tag includes the resource at request time. Therefore it is good for dynamic content pages. However, jsp:include tag can be used to include static as well as dynamic pages.

Note -> There is another way of including content of another resource. And we have already talked about that. Include directive. So, what is the difference? There are few differences. Let’s have a look below

Difference between include action and include directive

Include DirectiveInclude Action
It includes resource at translation time.includes resource at request time.
Include Directive is better for static pages.Include Action is better for dynamic pages.
includes the original content in the generated servlet.It calls the include method upon request.

Note -> If we have to include static content, include directive is better. If we have to include dynamic content, include action is better.

index.jsp

<html>

<h2>This is include action example</h2>  
  
<jsp:include page="displayDate.jsp" />  
  
<h2>End of the Page</h2>

<html>

displayDate.jsp

<html>

<% out.print("Current date is :" + java.util.Calendar.getInstance().getTime()); %>  

</html>

Output :