Difference between static include and dynamic include in JSP

Last day I was taking an interview in my company. The interview was for WebSphere Commerce. So I thought of going directly to WCS questions. But that guy said that he was working on WCS long back and he forgot everything in WebSphere Commerce. Then I thought I will ask some JSP questions as he was mentioned JSP in each and every project in his resume.

I thought of starting with a usual JSP interview question. So I asked him what is the difference between static include and dynamic include in JSP. His answer was partially correct. So I though I will write a post on what are the differences between static include and dynamic include in JSP. So the difference between static include and dynamic include are

  • The syntax for static include is <%@ include file=”filename.jsp” %> and the syntax for dynamic include is <jsp:include page=”filename.jsp” />
  • Static include is an inline inclusion. i.e., the contents of the file will be included at translation phase. It’s something like a copy and paste :-). In case of dynamic include the response of the file will be included to the original response at runtime. The file will be processed separately and only the response will become the part of the original files’ response.
  • Static include cannot have a dynamic filename. This is because the servlet container needs the files for inclusion, at translation phase itself. But dynamic include can have a dynamic filename. Here the file is getting included at runtime.
  • Static include cannot accept a parameter (What this parameter will do even if are passing it?). But dynamic include can accept a parameter. (Here we have some one to do something on the parameter).
  • Static includes are faster than dynamic includes.

I believe these are the differences between static include and dynamic include. I think I have covered all. If I missed anyone, please let me know.

Did you like this? If so, please
tell a friend
about it, and subscribe to the blog RSS feed.

Share/Save/Bookmark

If you enjoyed this post, make sure you subscribe to my RSS feed!




4 Responses to “Difference between static include and dynamic include in JSP”  

  1. 1 Arun

    Good post. I think you have covered almost all the differences.

  2. 2 M.Praveen

    Nice post, but u missed some more points such as

    –>What will happen if unfortunately the resource lost at static include?

    –>what is the original jsp or servlet file length in both cases?

    –>Which one is efficient for static content and dynamic content?

  3. 3 Albin Joseph

    Thanks Praveen, for pointing out the missing points.

    –>What will happen if unfortunately the resource lost at static include?
    In static include if the resource is not available, the container would throw an internal server error ie, Error 500 (At least in WebSphere). Ie, for static include the resource has to be present at translation phase. Once the page is compiled, even if the resource is not available, static include would work as expected. This is because the resource is already a part of the main file and it will not look for the file at run time.

    Dynamic include would throw a Page not found (HTTP Error 404), if the resource is not available at run time. The resource has to be present in the server every time we do a lookup for the file. This is because dynamic include uses a runtime inclusion of the file.

    –>what is the original jsp or servlet file length in both cases?
    In case of static include the original file size will be original file size included file size. Static include uses an inline inclusion. So the included file will become the part of original file at translation phase.

    In case of dynamic include, there will not be any change in the size of original file.

    –>Which one is efficient for static content and dynamic content?
    Static includes are more efficient for static content while dynamic include is more efficient for dynamic content.

  4. 4 Jayaram

    very nice article I found total information regarding this static and dynemic include.
    Thank you very much Albin Joseph

Leave a Reply