Easy to Learn Java: Programming Articles, Examples and Tips

Start with Java in a few days with Java Lessons or Lectures

Home

Code Examples

Java Tools

More Java Tools!

Java Forum

All Java Tips

Books

Submit News
Search the site here...
Search...
 
Search the JavaFAQ.nu
1000 Java Tips ebook

1000 Java Tips - Click here for the high resolution copy!1000 Java Tips - Click here for the high resolution copy!

Java Screensaver, take it here

Free "1000 Java Tips" eBook is here! It is huge collection of big and small Java programming articles and tips. Please take your copy here.

Take your copy of free "Java Technology Screensaver"!.

JSP include vs JSP action: What is faster for you?

JavaFAQ Home » JSP, Servlets Go to all tips in JSP, Servlets


Bookmark and Share

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

References: 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!


 Printer Friendly Page  Printer Friendly Page
 Send to a Friend  Send to a Friend

.. Bookmark and Share

Search here again if you need more info!
Custom Search



Home Code Examples Java Forum All Java Tips Books Submit News, Code... Search... Offshore Software Tech Doodling

RSS feed Java FAQ RSS feed Java FAQ News     

    RSS feed Java Forums RSS feed Java Forums

All logos and trademarks in this site are property of their respective owner. The comments are property of their posters, all the rest 1999-2006 by Java FAQs Daily Tips.

Interactive software released under GNU GPL, Code Credits, Privacy Policy