views:

446

answers:

2

I am beginning to break apart a large JSP file into a some smaller JSP pages so I can reuse this across other areas of the site.

I can take the approach of leaving as a large Monolithic JSP file that takes params and adjusts it's behavior accordingly. The other approach I can take is breaking it apart so that it's called via jsp:include.

What is the performance concern in creating additional request calls that are dispatched from within the server? Is it better performance wise to keep it as one jsp page?

+3  A: 

You should be using:

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

This adds the content of page.jsp at translation time and there is no overhead.

<jsp:include page="page.jsp" />

Your approach adds the content at runtime and adds a lot of overhead.

Nissan Fan
+5  A: 

The jsp:include is a runtime directive unlike the <%@ include ... %> directive which happens to be a compile time directive (translation time, actually). A compile time include directive is relatively harmless since JSPs are usually precompiled for production, or in the worst case compiled for every deployment of the application. For this reason, it is preferable to use the compile time directive for static files, since the files are not bound to change at runtime.

The runtime include directive on the other head, if misused, can result in some performance hit, especially for static files being included. This is primarily because the JSP container would have to then fetch the contents of the static file and include them in the response. Hence, reserve the usage of the runtime directive for the really useful scenarios where another servlet or jsp's response is to be included in the response, and not merely to make the code look good.

Vineet Reynolds