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.
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.
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)
[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 ]
Joined: Apr 09, 2007
hi thanks for reply,
Iam unable to get the above example. please anyone explain it in more detail.....
Joined: Mar 28, 2008
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.
Joined: Apr 09, 2007
Thanks for replying, Can anyone explain in what scenario will i choose a one among two ...
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.
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.
@ 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>
You can include a file to <jsp:include> that will update the cricket scores frequently which you cannot do with @ include
The greater danger for most of us is not that our aim is too high and we miss it, but that it is too low and we reach it