• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Question on performance with <jsp:include standard action

 
Ranch Hand
Posts: 469
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In HFSJ on page 406 it says There's an extra performance hit with every <jsp:include> .With the directive ,on the other hand,the hit happens only once --- when the including page is translated.

Does this mean if there are 2 jsp:includes in the main jsp there are 2 request dispatcher that apply include method ,there by causing performance hit? Where as with include directive if there are 2 include directive ,as the source is pasted inside the main jsp,the hit happens only once in spite of 2 includes?

Am I correct ? I wanted to understand this in detail.Can anybody please explain ?
 
Ranch Hand
Posts: 437
Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, Veena.

Does this mean if there are 2 jsp:includes in the main jsp there are 2 request dispatcher that apply include method ,there by causing performance hit? Where as with include directive if there are 2 include directive ,as the source is pasted inside the main jsp,the hit happens only once in spite of 2 includes?



Yes. If we are using two jsp:includes in the main jsp, at runtime the container has to load the two classes, instantiate them, initialize them, call service method on them, response will be added to the main jsp two times. This happens two times during runtime.

Incase of 'include' directive, during translation time, the jsp engine pastes the two include jsp files into the main jsp. This happens during page translation time, one time performance it.
 
Ranch Hand
Posts: 257
Hibernate Oracle Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey Chinmaya,

As we know that include directive provides better performance, even performance degradation on the first request can be eliminated by setting the load-on-startup value greater than 0.

my question here is- why exactly do we need jsp:include to be in j2ee when we know that it gives performance hit each time the page is invoked. Can you please give an example of real time scenario when we can not use include directive but include tag would fulfill the need/requirement.
 
Chinmaya Chowdary
Ranch Hand
Posts: 437
Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, Salil.

my question here is- why exactly do we need jsp:include to be in j2ee when we know that it gives performance hit each time the page is invoked. Can you please give an example of real time scenario when we can not use include directive but include tag would fulfill the need/requirement.



'jsp:include' will use in situations, where the files(images, text files, etc) chages frequently in main jsp. Suppose if our main jsp is having one jsp:include and if we deploy it and it works without any problems. Later, if we want to change the content of the jsp:include file, and we changed it. Now while accessing main jsp, the content that we change in the file, will reflect to the main jsp. This behavior is guaranteed, if we use jsp:include.

If we use 'include directive' instead of 'jsp:include', the change will not reflect(it is not guaranteed). Some containers/servers supports auto detection(this is not part of the specification) in that case it will reflect.

Generally we use 'include directive' where the file will not change and the position is fixed as the time goes.
 
Salil Vverma
Ranch Hand
Posts: 257
Hibernate Oracle Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Chinmaya,

As we know that when the jsp is called first time, it is converted to servlet (unless the load-on-startup value is set to greater than 0, in that case the jsp is converted to servlet at the application start up) and on the next consecutive calls the same servlet is invoked to get the response and while using jsp:include tag, container uses RequestDispatcher to include the contents in the parent jsp

I am bit confused now, "wouldn't the container use the same servlet (converted from jsp on first request) to fulfill the next upcoming request from dispather rather than taking the fresh jsp and converting them to servlet each time to fulfill the request? and if it uses the same servlet converted on first call, how will the latest changes in jsp would appear in the parent jsp?"

 
Chinmaya Chowdary
Ranch Hand
Posts: 437
Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, Salil.

When 'jsp' is converted into servlet(either by first request, or load-on-startup), then it is eligible for servlet. When next request comes, container calls the 'service' method. This happens unless there is no change in the 'jsp' file. If there is a change in 'jsp' container has to repeat the lifecycle methods.
 
Salil Vverma
Ranch Hand
Posts: 257
Hibernate Oracle Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Chinmaya,

I think, the explanation that you gave, make sense. Just one more query, whether the verification about the change in the jsp file is done on each request in case of jsp:include tag or container implements some listener, keeps track of changes in the jsp file and on the next invocation (after the change) forces the request go through repetition of life cycle?



 
Veena Pointi
Ranch Hand
Posts: 469
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
As per my understanding of what I read in HFSJ,jsp:inlude is translated as run time call in generated servlet inside parent jsp page...so each time request comes in ,this run time call is executed? Please correct me if I am wrong.
 
Chinmaya Chowdary
Ranch Hand
Posts: 437
Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, Salil.

If jsp file contains jsp:include, jsp engine translates it(during translation time) into and after passing all life cycle steps, it is eligible for servlet.

For next request container calls the 'service' method and which calls the _jspService method passing request, response objects. When container sees include call, I think it makes a condition, whether the source file of 'test.jsp' is modified or not, using checksum or listeners(I am not sure which mechanism it uses)? If yes, repeat the life cycle steps. If no, call its service method.
 
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Does this mean that checking the updated jsp file is compiler dependent and not jsp specification related?
What if the feature is not supported by the container?

please clear my doubt.

Thanks in advance.
 
Sheriff
Posts: 9707
43
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When a JSP page is modified, it is the responsibility of the container to recompile the JSP before serving the next request whether it be a client request or dispatched request (using RequestDispatcher or jsp:include or jsp:forward).

There is another use of using jsp:include over include directive. The value of file attribute of include directive cannot be dynamic. So while writing the JSP page you have to decide which page to include. But with jsp:include, the page to include can be specified at request time. So for one request one page can be included and for another request some other page can be included...
 
Salil Vverma
Ranch Hand
Posts: 257
Hibernate Oracle Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Ankit,

Thanks for confirming that it is the responsibility of the container to check whether a jsp file was updated and make it available as a servlet before the next request for this jsp reaches to the container.

I think, while using the jsp:include tag we can include request parameters using param tag while using using include directive we can not. Kindly correct me if I am wrong.



 
reply
    Bookmark Topic Watch Topic
  • New Topic