This week's book giveaway is in the HTML Pages with CSS and JavaScript forum.
We're giving away four copies of Testing JavaScript Applications and have Lucas da Costa on-line!
See this thread for details.
Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Include directive

 
Ranch Hand
Posts: 112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As per understanding the jsp include directive(ie <%@ include ) is processed at jsp translation time. This would mean that the code from the included file would be copied over to the including file and then the jsp would be compiled as a single servlet .class file.

This further means that if i make any changes in the included file then that change is not visible to the jsp and the jsp would still show the old file behavior only.

I tried a small example and I am seeing behavior where the included file is reflected in the jsp as soon as I edit the included file.

e.g Here Dummy.jsp includes include.html

step 1. I start the server and access Dummy.jsp
It shows the content of include.html
step 2. I made changes to include.html
I observe that the Dummy.jsp is now showing the latest content from include.html(I didn't redeploy or restart the server)

Can anynody tell me if I understanding of include directive is wrong. Also let me know what I am missing.

Code of Dummy.jsp is


Code of include.html
 
Ranch Hand
Posts: 312
MS IE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The Servlet container that compiles-and-runs JSP file sees changes to content then it re-compiles the modified files. This in turn will cause the changes to be reflected in the next reload.
 
Pankaj Kumarkk
Ranch Hand
Posts: 112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am not sure I am following the answer. I wanted to know following:
1. As per the JSP specification, what is the behavior expected of include directive
2. Is a servlet container expected to track for changes to content included through include directive

I wanted to know the reason behind this behavior which I mentioned in the original post
 
Ranch Hand
Posts: 1512
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What servlet/JSP container are using? Some containers can automatically to automatically detect when a JSP has changed, and I suspect your container does have a setting that has turned this feature on.

Pankaj Kumarkk wrote:I am not sure I am following the answer. I wanted to know following:
1. As per the JSP specification, what is the behavior expected of include directive
2. Is a servlet container expected to track for changes to content included through include directive

I wanted to know the reason behind this behavior which I mentioned in the original post

 
Pankaj Kumarkk
Ranch Hand
Posts: 112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am using tomcat.
However this should not matter as I am changing a html file and not jsp.

As per my understanding a jsp will re-translate and re-compile only if it's modified timestamp has changed.

Just to restate the issue: I have a jsp which include<%@s a html file(using include directtive ie <%@ include)
Question: Will the jsp pick up the latest html as and when I change the html file(without retstart of server)
 
Marshal
Posts: 67425
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Pankaj Kumarkk wrote:Question: Will the jsp pick up the latest html as and when I change the html file(without retstart of server)



What happened when you tried it?
 
Pankaj Kumarkk
Ranch Hand
Posts: 112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am seeing that the jsp is picking up latest html file as soon as I modify the html file. I have given the sample jsp and html file code also and it can be tried very quickly
 
Bear Bibeault
Marshal
Posts: 67425
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So you have seen the behavior with your own eyes. What's the issue?
 
Pankaj Kumarkk
Ranch Hand
Posts: 112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The issue is with understanding of the concept. Since include directive are processed at translation time therefore the jsp should not pick a html(changed at runtime). Is there a gap in understanding or does the jsp/servlet spec say this.
 
Bear Bibeault
Marshal
Posts: 67425
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Changes to the JSP can also happen at run time, after the original translation, and yet they get updated.
 
Pankaj Kumarkk
Ranch Hand
Posts: 112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am not clear of the reply. Can you please elaborate.
Are you saying that the jsp will get retranslated again even if there are no changes to the jsp file. (Note: In the current case the html file is getting changed at runtime and not jsp)
 
Bear Bibeault
Marshal
Posts: 67425
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, that's not what I'm saying.

I'm saying that the container can detect when a JSP file has changed and re-translate it when that happens, why does it surprise you that it can do the same for other files?
 
Pankaj Kumarkk
Ranch Hand
Posts: 112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am surprised because that's not what jsp/servlet spec(as per my understanding) says. I would like to know what is the correct behavior for a include directive.

In my books, the spec drive the implementation behavior and not the other way around.
So either the spec are wrong(which i am sure is not the case) or my understanding of spec is wrong or tomcat implementation is wrong(highly unlikely)

 
Ranch Hand
Posts: 113
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Pankaj,

I think I read about this behavior in "Head First Servlets & JSP" book and there it was said that new Tomcat versions are "smart" enough to detect that the included parts in jsp(using include directive) have changed and the container is taking care of this change by regenerating the servlet code from the jsp and the new included component.

I do not remember in which version of Tomcat this feature was included but if I am not wrong 5.x and 6.x are already "smart" containers.
In the book was explained that the specification is not guaranting that this behavior will be present, so it depends on the used container.
If you cannot find the source in the book just say and I will try to dig it up for you.

Regards
 
Pankaj Kumarkk
Ranch Hand
Posts: 112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the explanation. If include directive behavior is vendor dependent then what is the difference between include directive and jsp:include action. Why I would chose one over another.
I thought that i should chose include directive if I have some static content as the performance of include directive is faster than jsp:action (as one is translation time and other is runtime)

Then the only reason for choosing jsp:action would be when your jsp page size is too big(>64k) and you want to seperate it into multiple jsps.
 
Stoian Azarov
Ranch Hand
Posts: 113
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think that even after introducing this auto update functionality in Tomcat container the performance is still the same(although I cannot confirm that with examples).
Using include directive still creates servlet that includes the whole code inside. And <jsp:include> standard action is still making runtime call. The only difference is that every time when you change some of the included elements(pages) the jsp pages will get automatically translated to servlets and compiled.

I don't think that you will change the code in the included static html pages very often, so the performance will suffer only when you make such refactoring.
Of course every situation should be analyzed separately.
 
Those who dance are thought mad by those who hear not the music. This tiny ad plays the bagpipes:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic