Difference between JSP include directive and JSP include action
Last modified on October 5th, 2014 by Joe.
- <%@ include file=”filename” %> is the JSP include directive.
At JSP page translation time, the content of the file given in the include directive is ‘pasted’ as it is, in the place where the JSP include directive is used. Then the source JSP page is converted into a java servlet class. The included file can be a static resource or a JSP page. Generally JSP include directive is used to include header banners and footers.
The JSP compilation procedure is that, the source JSP page gets compiled only if that page has changed. If there is a change in the included JSP file, the source JSP file will not be compiled and therefore the modification will not get reflected in the output.
- <jsp:include page=”relativeURL” /> is the JSP include action element.
The jsp:include action element is like a function call. At runtime, the included file will be ‘executed’ and the result content will be included with the soure JSP page. When the included JSP page is called, both the request and response objects are passed as parameters.
If there is a need to pass additional parameters, then jsp:param element can be used. If the resource is static, its content is inserted into the calling JSP file, since there is no processing needed.
I believe there is a limit of 64kb size in JVM for method. So the include directive can run into trouble as its all one method. Whereas the action is considered a separate process.
Thanks a lot Jignesh
Hey,thanks for the explanation above! However, i’ve got one question.. my static change in the included file was updated when i’m using them in JSP include directive.. I came across the issue that time stamp attribute must be disabled in the JSP container for Tomcat web server in order to avoid this issue. Would you be able to assist me as i had a hard time searching online for a solution..many thanks for your help!
Hi i have a doubt . I am having two jsp pages A and B.In A.jsp i am declaring int i=5; and including B.jsp(in this i am having some statements) and Printing using out,println(i) in A.jsp. what is the output when we use directive include and action include …? can any body let me know
what is the jsp life cycle process,i want to know how containers checking whether the jsp page is modified or not?
good explanation…thank you very much..
I am a banker with interest in programming. I am trying to learn JSP by reading ebooks. I try the examples given in the books. Although I am able use , but in case of jsp: include – I am not able to run the page. This may be because of problem with URI . Can you please give me a comple example with location of included file ?
Please also name good ebook on JSP that is freely available on net.
With thanks – S P Sarkar
I have 1 question that,
What if there are 2 jsps a.jsp and b.jsp which includes one other jsp having code int a =10; in its scritptlet
a.jsp is having directive include and b.jsp is having include action then which jsp will print value of System.out.println(a)?
i m using netbeans 6.7.1 for jsp and servlet. my problem is that my logic code does not work in jsp page, it can only displays the design and not logic. i tried in scriptlet, expression anything, whats the problem?????
JSP include directive is used to include header banners and footers.
This line is very use for any user.I thing that this line is proper understanding the difference ………..
The above is my sum.jsp
I have one question ..
Assume filename is some jsp file then
how many servlet file will be created at run time for below tags
Have a small doubt…Will appreciate if you reply.
Can we use jsp include action to call an action class in struts??
very nice explanation.
Thanx for clearing the concept in the most easy way…
Very nice explanation which is very simple to understand.
Simple and clear explaination. thanks
hi if the including jsp content is keep on changing,in this case which include i have to use whether directive or action tag?
very best diferent in the WTED
I have a unique issue. We’re using a JSP to serve up a dynamic home – landing page for our web app. The dynamic home-landing pages are all HTMLs. We’d like to leave them in the htdocs folder on the web server vs. having to include them on the App Server in the same folder as the driving JSP.
We can use <jsp:include page=="” /> include action or a <c:import url="” /> TAG but in either case the HTMLS must be located in the same folder as the JSP file on the App Server side of the fence.
How can I include the dynamic home-landing pages in the JSP leaving them in the htdocs folder back on the Web Server without paying the performance penalty to retrieve them on every runtime iteration? Any changes to the HTMLS would also need to be displayed with a re-compile of the JSP.
Hey, I have a question…
I want to send a request from a JSP page to a servlet….and then I want servlet to send response to the same JSP page….
I am not getting the servlet response on the same JSP page….
Please help me find out the solution…
i hav one question?
how to display errors in page with out action
How can I include the dynamic HTML’s which are residing in the htdocs folder on the Web Server in the JSP and also retrieve them on every runtime iteration as any changes to the HTMLS also need to be displayed in the JSP without neccesarily re-compiling the JSP.
Thanks for your Superb explanation.
like to share the diff. in another way,which I found in net.
JSP include directive –
if a declartion (variable/method) exist in both page (Source page & Included page)
error will be thrown.
JSP include action – Since works like a function call , duplication error wont occur.
explanation is not good
Very nice explanation :)
then wat u r expecting..???
Have you ever seen a Servlet exception (Stream closed) while you including a jsp (in any method) ? I am facing such an issue for a long time. I have page definition tags includes another JSPs and getting a ‘Stream closed’ exception..!!!
email : linuxeverywhere at gmail
good job joe
Then Definitely you have to use the JSP Include Action Tag element.
thank you so much
Correct… I got the same problem. Thanks for hint :)
plz. tell me the correct difference between class and constructor
remove the girls photo add from this site.because the student or employee are not able to open this site in college or at work place.
can you please give the contents of B.jsp file.
use a forward slash(/) before included file inditing that the system will interpret the url relative to the home directory of the web server
or else use a absolute url as
i also came across the same problem.Were u able to find a solution for it?Have you tried with GlassFish Server?
Very useful….Thanks………..Keep up the good work……..
Where does the code goes in side servlet of both( Page directive and )after page parsed and servlet made by JSP container?
Thanks for the nice explanation. It really helped me a lot.
if you use include directive,then it will not generate any problem.Always remember ,include directive inserts the file at the time the jsp page is translated into a servlet whereas include action inserts the file at the time the page is requested.So in the case of directive include ,b.jsp has the file a.jsp ,it means you can access the variable i in the b.jsp.But in the case of action include sometimes it will work and sometimes it will not work….because action is considered as a separate process.But you can resolve that problem using the concept of and you should use request.getParameter(“i”) in the b.jsp….
when I change the page that is include.. those changes are reflecting
with include directive why so ?