• 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

Difference between jsp:include and include directive.

 
Ranch Hand
Posts: 112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi friends,
I have read many books regarding the usage of jsp:include tag and include directive. But, i am unable to get an in-depth idea (purpose) of these tags. In what situations will i probably choose a one among them.

Can any one, present me with a real time example instead of a bookish example.

Thanks,
Venkat
 
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Could this FAQ help ?
 
Venkata Sirish
Ranch Hand
Posts: 112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for replying buddy,

Could anyone, explain the same with a real time example.




Thanks in advance,
Venkat
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A simple example would be with a header. If you include a page using the include directive, changes you make to the included file will not be reflected. If you include a page using the include action, changes made to the included file will be reflected.

header.jsp

directive.jsp

action.jsp


Accessing the directive.jsp several times should not update the time. (in Tomcat, it will change... a container which does not check the included files timestamp will not update it)
 
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
[Edit: thread hijack removed. al, please start new topics for your own questions, unless they are continuations of the same (not related) issues. I've spawned your question off into a new post.]
[ April 03, 2008: Message edited by: Bear Bibeault ]
 
Venkata Sirish
Ranch Hand
Posts: 112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi thanks for reply,

Iam unable to get the above example. please anyone explain it in more detail.....


Regards,
venkat
 
al langley
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'll give it a shot. based on the above poster's example.
When I go to the directive.jsp page, this is what appears on my browser:

[Time now is Thu Apr 03 19:29:47 EDT 2008]

I then close the browser, and go back to it five minutes later, and it says the SAME thing (Well, according to the poster of the example, it should say the same thing, unless your container checks for timestamps).

[Time now is Thu Apr 03 19:29:47 EDT 2008]. SAME as before

On the other hand, if I did the same thing with the action.jsp, the time would change.

[Time now is Thu Apr 03 19:29:47 EDT 2008] first time
[Time now is Thu Apr 03 19:34:47 EDT 2008] second time, accessed five minutes later


The reasoning for this is how the container handles the directive include(<%@ include...) versus how the container handles the include standard action (<jsp:include...).
It has to do with how the jsp gets turned into a servlet.

When using the directive, the code from the included jsp page (header.jsp) gets shoved into the directive.jsp, then the container
turns it into a single servlet.

On the other hand, using jsp:include, the code from the included jsp page (header.jsp) isn't shoved into action.jsp. Instead, the container
generates two servlets (one for header.jsp and one for action.jsp). A method is then placed into the servlet created from the action.jsp. This method
tells the container to call the servlet created from the header.jsp. The container then combines both results into one page.
 
Venkata Sirish
Ranch Hand
Posts: 112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for replying,
Can anyone explain in what scenario will i choose a one among two ...
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You've been able to get quite a few responses to your questions.

Why don't you give us a couple examples of what you think each of these would be good for? If you're examples are good, we'll let you know. If not someone might be able to point you to a good tutorial or book.
The folks here are happy to help someone out but we like to see some effort on your part too.

-Ben
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Include directive can only be used to include static content. The value of the property "file" must be "path+ file name". The file must really exist, otherwise you get file not found exception at run time. The file could have any name: ".html", ".jps", or even ".foo".

You are not allowed to have a servlet included: if you have SampleServlet, and this servlet could be accessed via ".../SampleServlet". But if you try to include this servlet with include directive like file="/SampleServlet" , you get file not found error at run time.

But including servlet with jsp:include action is ok: page="/SampleServlet". jsp include action could be used to include not only static but also dynamic content.




 
Ranch Hand
Posts: 162
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
@ include is static include. It is inline inclusion. We cannot have a dynamic filename for directive include. <jsp:include> is dynamic include. Here the included file will be processed as a separate file and the response will be included. We can have a dynamic filename for <jsp:include>


Example:
You can include a file to <jsp:include> that will update the cricket scores frequently which you cannot do with @ include
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"sss wang", please check your private messages for an important administrative matter.

And both sss and Sujai Kaarthik, please read this for information in relying to older, out-dated posts.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic