Difference between JSP include directive and JSP include action

09/05/2008
  • <%@ include file=”filename” %> is the JSP include directive.
    At JSP page translation time, the content of the file given in the include directive is ‘pasted’ as it is, in the place where the JSP include directive is used. Then the source JSP page is converted into a java servlet class. The included file can be a staticĀ resource orĀ a JSP page. Generally JSP include directive is used to include header banners and footers.

    The JSP compilation procedure is that, the source JSP page gets compiled only if that page has changed. If there is a change in the included JSP file, the source JSP file will not be compiled and therefore the modification will not get reflected in the output.

  • <jsp:include page=”relativeURL” /> is the JSP include action element.
    The jsp:include action element is like a function call. At runtime, the included file will be ‘executed’ and the result content will be included with the soure JSP page. When the included JSP page is called, both the request and response objects are passed as parameters.

    If there is a need to pass additional parameters, then jsp:param element can be used. If the resource is static, its content is inserted into the calling JSP file, since there is no processing needed.

This JSP tutorial was posted on 09/05/2008.
Ads by Google

46 comments on “Difference between JSP include directive and JSP include action

  1. I believe there is a limit of 64kb size in JVM for method. So the include directive can run into trouble as its all one method. Whereas the action is considered a separate process.

    • Correct… I got the same problem. Thanks for hint :)

  2. Excellent explanation..

    Thanks a lot Jignesh

  3. Hey,thanks for the explanation above! However, i’ve got one question.. my static change in the included file was updated when i’m using them in JSP include directive.. I came across the issue that time stamp attribute must be disabled in the JSP container for Tomcat web server in order to avoid this issue. Would you be able to assist me as i had a hard time searching online for a solution..many thanks for your help!

    • Hello Dear,
      i also came across the same problem.Were u able to find a solution for it?Have you tried with GlassFish Server?

  4. Hi i have a doubt . I am having two jsp pages A and B.In A.jsp i am declaring int i=5; and including B.jsp(in this i am having some statements) and Printing using out,println(i) in A.jsp. what is the output when we use directive include and action include …? can any body let me know

    • can you please give the contents of B.jsp file.

  5. what is the jsp life cycle process,i want to know how containers checking whether the jsp page is modified or not?

  6. I am a banker with interest in programming. I am trying to learn JSP by reading ebooks. I try the examples given in the books. Although I am able use , but in case of jsp: include – I am not able to run the page. This may be because of problem with URI . Can you please give me a comple example with location of included file ?

    Please also name good ebook on JSP that is freely available on net.
    With thanks – S P Sarkar

    • use a forward slash(/) before included file inditing that the system will interpret the url relative to the home directory of the web server
      eg

      or else use a absolute url as

  7. I have 1 question that,
    What if there are 2 jsps a.jsp and b.jsp which includes one other jsp having code int a =10; in its scritptlet
    a.jsp is having directive include and b.jsp is having include action then which jsp will print value of System.out.println(a)?

  8. i m using netbeans 6.7.1 for jsp and servlet. my problem is that my logic code does not work in jsp page, it can only displays the design and not logic. i tried in scriptlet, expression anything, whats the problem?????

  9. JSP include directive is used to include header banners and footers.
    This line is very use for any user.I thing that this line is proper understanding the difference ………..

  10. SUM OF TWO NUMBERS IS

    h1{color:#778899}
    .visitor{color:#883322;font-family:GraublauWeb;}

    SUM OF TWO NUMBERS IS
    number of visitors of this site are

    GO TO HOME

  11. input two numbers

    h1
    {
    text-align:center;
    font-family:Viner Hand ITC;
    color:#778899;
    }
    input.red {background-color: #cc0000;}

    Enter numbers

    footer

    GOOD BYE

    SUM OF TWO NUMBERS IS

    h1{color:#778899}
    .visitor{color:#883322;font-family:GraublauWeb;}

    SUM OF TWO NUMBERS IS
    number of visitors of this site are

    GO TO HOME

    welcome

    I AM IN MIDDLE

    My proble is here in middle.jsp i included the sum.jsp bu using which is a dynamic page eventhough i make changes in the sum.jsp then getting reflected in my output y like that? please help me where i went wrong?
    Thank for ur help in advance.

  12. Joe,

    I have one question ..

    Assume filename is some jsp file then

    how many servlet file will be created at run time for below tags

    1)
    2)

  13. Joe,

    Have a small doubt…Will appreciate if you reply.

    Can we use jsp include action to call an action class in struts??

  14. Thanx for clearing the concept in the most easy way…

  15. Very nice explanation which is very simple to understand.

  16. Simple and clear explaination. thanks

  17. hi if the including jsp content is keep on changing,in this case which include i have to use whether directive or action tag?

    • Then Definitely you have to use the JSP Include Action Tag element.

  18. I have a unique issue. We’re using a JSP to serve up a dynamic home – landing page for our web app. The dynamic home-landing pages are all HTMLs. We’d like to leave them in the htdocs folder on the web server vs. having to include them on the App Server in the same folder as the driving JSP.

    We can use <jsp:include page=="” /> include action or a <c:import url="” /> TAG but in either case the HTMLS must be located in the same folder as the JSP file on the App Server side of the fence.

    How can I include the dynamic home-landing pages in the JSP leaving them in the htdocs folder back on the Web Server without paying the performance penalty to retrieve them on every runtime iteration? Any changes to the HTMLS would also need to be displayed with a re-compile of the JSP.

    Please reply to mhall@ltcpartners.com

    Thanks!

  19. Hey, I have a question…

    I want to send a request from a JSP page to a servlet….and then I want servlet to send response to the same JSP page….

    I am not getting the servlet response on the same JSP page….

    Please help me find out the solution…

    Regards!

  20. i hav one question?
    how to display errors in page with out action

  21. How can I include the dynamic HTML’s which are residing in the htdocs folder on the Web Server in the JSP and also retrieve them on every runtime iteration as any changes to the HTMLS also need to be displayed in the JSP without neccesarily re-compiling the JSP.

  22. like to share the diff. in another way,which I found in net.

    JSP include directive -
    if a declartion (variable/method) exist in both page (Source page & Included page)
    error will be thrown.

    JSP include action – Since works like a function call , duplication error wont occur.

  23. Hi Joe,
    Have you ever seen a Servlet exception (Stream closed) while you including a jsp (in any method) ? I am facing such an issue for a long time. I have page definition tags includes another JSPs and getting a ‘Stream closed’ exception..!!!
    email : linuxeverywhere at gmail

    • plz. tell me the correct difference between class and constructor

  24. remove the girls photo add from this site.because the student or employee are not able to open this site in college or at work place.

  25. Very useful….Thanks………..Keep up the good work……..

  26. Where does the code goes in side servlet of both( Page directive and )after page parsed and servlet made by JSP container?

  27. Thanks for the nice explanation. It really helped me a lot.

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>