Reputation: 1686
We have a web page, running on a glassfish server. In our jsp file we have a lot of includes like the one below.
<jsp:directive.include file="johndoe/foobar.jspf"/>
These files are included according to the user choice. Our jsp file is basically like this:
<jsp:root version="2.1" xmlns:c="http://java.sun.com/jstl/core_rt"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:jsp="http://java.sun.com/JSP/Page"
xmlns:webuijsf="http://www.sun.com/webui/webuijsf">
//some unimportant codes here
<c:if test="${sessionScope.loadAvgTest}">
//some unimportant codes here
<f:subview id="reports15">
<jsp:directive.include file="siforms/sysinfoform.jspf"/>
</f:subview>
//some unimportant codes here
<f:subview id="reports16">
<jsp:directive.include file="siforms/sysinfoformscheduled.jspf"/>
</f:subview>
//some unimportant codes here
</c:if>
//some unimportant codes here
<c:if test="${sessionScope.bandwidthTest}">
//some unimportant codes here
<f:subview id="reports17">
<jsp:directive.include file="mailforms/mailfilter.jspf"/>
</f:subview>
//some unimportant codes here
<f:subview id="reports18">
<jsp:directive.include file="mailforms/mailfilterscheduled.jspf"/>
</f:subview>
//some unimportant codes here
</c:if>
....
There are approximately 80 if statements like this each one containing 2 inculdes. When I removed a lot of these if clauses and leaved only a few if and a few include memory usage was fine. But as I use more if clauses and more includes the memory usage grows. Any ideas how I can optimize the code or how I can make configuration changes to the servlets configuration to lower the memory usage?
Upvotes: 0
Views: 734
Reputation: 1686
Using jsp:include
instead of jsp:directive.include
solved the problem.
As far as I have learned from my research jsp:directive.include
(include directive) includes the file into the JSP page at compile time whereas jsp:include
includes the output at runtime.
I have found that, include action (runtime include) runs a bit slower
yet it is preferred generally because it save a lot of memory of the system.
(source)
Upvotes: 1
Reputation: 108939
You're using JSF. At view creation time, if an if
statement evaluates to true, the JSF controls on the page will be added to the component tree. For server-side state saving, these UIComponent instances and their state will (by default) be persisted in the user's session. The more controls you add, the more memory you are going to consume. By default, a number of old views are persisted in the session.
You could try:
com.sun.faces.numberOfViewsInSession
and com.sun.faces.numberOfLogicalViews
or equivalent initialization parameters for your implementation)javax.faces.STATE_SAVING_METHOD
- this comes with security concerns and may alter application behaviour)Upvotes: 0