JSP - The memory consumption

I'm not going to reiterate what most of the people already know about the difference between jsp include directive <%@ include... /> and jsp include action . One difference which struck to me and which, I want to share with you all is that action is good in terms of memory consumption. Before going into the details of what I've just mentioned, do remember that the jsp directive includes all the files at compile time, and when a request comes, the jsp (servlet) get's instantiated and is loaded into the heap memory. Similarly, for jsp action, the process happens at run time.

Now let’s take an example where, you have a member.jsp file. And you want to include another file permanentAddress.jsp, when permanentAddress flag is set to true. Similarly include memberDetails.jsp, when details flag is set to true, and planDetails.jsp, when plan flag is set to true.

In case of jsp directive, all the content of permanentAddress.jsp, memberDetails.jsp, and planDetails.jsp will get loaded into member.jsp at compile time and the entire jsp (servlet) will get instantiated and will use heap space accordingly. Then at run time it will execute the functions as per the checks (if statements).

In case of jsp action, if conditions will get evaluated first, and if it returns true, the if block will get executed and corresponding jsp will get included. As a result both the member.jsp and other jsp will get instantiated, and will use heap space accordingly. It won't use heap memory for all the jsps where if block is not getting executed and in a way it's saving some meomory on heap.

Not to mention that, jsp directive is faster to jsp action as it is including the content at compile time where as jsp action does it at run time.

 

Comments

Popular posts from this blog

Spring Security - Adding more information to the authenticated user.

Hibernate Difference between update() and merge()

Running tomcat maven plugin in Debug mode (in STS, Eclipse and MyEclipse)