Thursday, May 28, 2009

JSP include tag versus include directive

The first thing to note is that if either of these directives fails, then the page stops loading.

The directive will accept a relative path from the current location; the tag must have a path that starts with /, which is the root of the web application, not the root of the server.

The difference between the two is how they handle dynamic content. The tag includes the output of the dynamic reference in the page at runtime; the directive includes the contents of the dynamic reference when the including JSP is compiled into a servlet.

I am hard pressed to devise an example using JSPS that has different output for the tag and the directive. The directive can only include actual files, so the directive is useless if CGI or PHP files are to be included.

If the tag includes a reference to a servlet, be sure that the servlet does not close the output stream. This is a problem for a servlet that forwards to a JSP, since the output stream is closed after the forward is complete.

Both by-pass the security constraints in the web.xml file. Both can access WEB-INF, directly.

Both can only include resources that are in the web application.



I just read on another site that the difference is when they are loaded.

The tag loads at runtime.

<jsp:include page="includedPage" /> 

The directive loads at compile time.

<%@ include file="banner.jsp" %> 

From http://stackoverflow.com/questions/9188478/how-to-implement-a-include-jsp-tag

No comments:

Post a Comment

Followers