JSP include vs JSP action. Probably you do not know that..
80 % Java programmers never heard that there are two mechanisms for calling a page from another JSP page. And from the rest 20 % who heard something (or knows definitely) many do not know what is better for optimal performance and why
How to choose the right include mechanism for a JSP page?
There are two possible ways to insert a file in a JSP page. They are listed below:
1. include directive <%@ include file="javafaq.jsp" %>
2. include action <jsp:include page="javafaq.jsp" flush="true" />
The include directive includes the content of the file during the compilation phase (JSP-->servlet-->class file) where as include action includes the content of the file during execution/request processing phase.
For include directive, JSP Engine adds the content of the inserted page at translation phase, so compilation does not have an impact on performance during run time. Some people will say: "Yes, the first method is faster". Not necessarily! Do not forget that two files are bigger than one and it takes time to load them into JSP engine.
For include action, JSP Engine adds the content of the inserted page at run time which imposes extra overhead.
Finally, it is up to you to choose which case is better for you - include directive or include action.
If you need some pages not so often, then second method could be better. It is also better if your choice of second file depends on program logic - for example if you have 10 different cases and every case requires different file.
The first choice is preferable when you just need all the time same file, where you probably hide most of the code (for example like library) and main file is responsible only for logic..
Some J2EE code examples on our site
JavaServer Pages TM 2.1, Final Release of this Specification
English is not
native language for me, so if you find an error, please correct me!
1693 bytes more | comments? | | Score: 0