aspose file tools*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes Question on performance with <jsp:include standard action Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "Question on performance with <jsp:include standard action" Watch "Question on performance with <jsp:include standard action" New topic
Author

Question on performance with <jsp:include standard action

Veena Pointi
Ranch Hand

Joined: Jun 20, 2002
Posts: 442
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 ?


SCJP1.4
"Continuous effort - not strength or intelligence - is the key to unlocking our potential."
*Winston Churchill
Chinmaya Chowdary
Ranch Hand

Joined: Apr 21, 2008
Posts: 432
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.
Salil Vverma
Ranch Hand

Joined: Sep 06, 2009
Posts: 255

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.


Regards
Salil Verma
Chinmaya Chowdary
Ranch Hand

Joined: Apr 21, 2008
Posts: 432
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

Joined: Sep 06, 2009
Posts: 255

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

Joined: Apr 21, 2008
Posts: 432
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

Joined: Sep 06, 2009
Posts: 255

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

Joined: Jun 20, 2002
Posts: 442
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

Joined: Apr 21, 2008
Posts: 432
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.
Niteen Patil
Ranch Hand

Joined: Oct 27, 2009
Posts: 45
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.
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9313
    
  17

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...


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
Salil Vverma
Ranch Hand

Joined: Sep 06, 2009
Posts: 255

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.



 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Question on performance with <jsp:include standard action