Difference Betwixt Include Directive Too Include Activeness Inwards Jsp Servlet

Difference betwixt include directive together with include action is ane of the well-nigh popular JSP interview questions together with too asked equally What is divergence betwixt page include together with file include inwards JSP.  Similar to difference betwixt frontward together with ship redirect  together with URL encoding vs URL rewriting, this is too asked at beginners level. Here nosotros volition come across page include vs file include inwards detail. Both include directive together with include action is used to include output of a static page e.g. HTML or a dynamic page e.g. jsp inside only about other jsp file. In this JSP tutorial nosotros volition come across what is include directive inwards JSP together with what is include action together with difference betwixt include directive together with include action. This JSP interview question is generally asked during 2-4 years sense inwards Java J2EE. 

By the way this article is inwards continuation of my other posts on J2EE interviews similar Top 10 Spring Interview Questions together with Top 10 Servlet Interview questions. If you lot are interested on Core coffee or multi-threading than you lot tin banking concern jibe Top twenty Core Java Interview questions.


Include activeness vs Include directive inwards JSP

In this section, nosotros volition inwards especial how pages are included using include activeness together with directive, how JSP pages are translated into Servlet together with how to utilisation include activeness together with directive along amongst a yoke of divergence betwixt them.


How JSP (Java Server Pages) works

ifference betwixt include directive together with include activeness Difference betwixt include directive together with include activeness inwards JSP Servletheap retentiveness by the spider web container. Code written using JSP annunciation e.g. <%!&gt; goes into trunk of generated servlet equally instance variable together with all code from trunk goes into service() method of generated Servlet. In case of tomcat web-server these generated servlet files goes within locomote directory. In brusk JSP pages has three steps to teach executed translation-->Compilation -->Execution. Also JSP file volition exclusively survive re-compiled exclusively if at that spot is a alter inwards JSP file.

What is include directive inwards JSP

Include directive inwards JSP is used to import a static file or dynamic file e.g. JSP within only about other JSP. Most common example of include directive is including header together with footer inwards JSP. Include directive is too called file include because resources to survive included is specified using file attribute equally shown inwards below instance of include directive:

<%@ include file="loan.jsp" %>

The code written inwards loan.jsp volition survive included equally it is inwards the jsp file which included it during JSP translation time together with than merged code is teach compiled to generate Servlet which is later on used to server request. Include directive is too refereed equally static import together with it acts similar #include from C or C++. file attribute is used specify resources to survive included together with tin survive specified inwards either relative URL or absolute URL. Since resource included using include directive is included during translation fourth dimension together with jsp doesn't compile if at that spot is any change inwards included file. So include directive is non suitable to include dynamic resources because if included file changes betwixt multiple asking exclusively one-time value is used always. include activeness is meliorate selection for including dynamic resources which nosotros volition come across inwards side past times side section.

What is include activeness inwards JSP

Include activeness inwards JSP is only about other way of including a jsp file within only about other jsp file. Included resources is specified using page attribute equally shown inwards below instance :

<jsp:include page="loan.jsp" %>

here contents of loan.jsp volition survive included during asking fourth dimension instead of translation time together with whatever alter in loan.jsp volition reverberate immediately. Due to this nature include activeness is too called dynamic include inwards JSP. It too referred equally page includes because of page attribute used to specify included resource.

Difference betwixt include directive together with include activeness inwards JSP

include directive is <%@ include file="loan.jsp" %> together with include activeness inwards JSP is <jsp:include page="loan.jsp" %>
As I said before this is ane of pop servlet jsp interview question together with generally asked to Junior or mid-senior Java programmers during interviews. Following are only about mutual differences betwixt include activeness together with include directive inwards JSP:

1. Resource included past times including directive is loaded during jsp translation fourth dimension spell resources included past times including activeness is loaded during asking time.
2. Any alter on included resources volition non survive vid d d v v c cfm gnfnffggs sible inwards instance of include directive until jsp file compiles
again. While inwards the instance of include in ane lawsuit to a greater extent than whatever alter inwards included resources volition survive visible inwards side past times side request.
3. include directive is static import spell include activeness is dynamic import
4. include directive uses file attribute to specify resources to survive included spell including activeness utilisation page attribute for the same purpose.

5.  Another divergence suggested past times N. Satish babu in comment department is that value of the attribute to  JSP include activeness tin be  dynamic together with asking fourth dimension seem together with you lot tin too exceed parameter to the file which you lot are going to include using include activeness e.g.

<jsp:include page="header.jsp">
<jsp:param name="some" value="thing"/>
</jsp:include>



That’s all on this pop jsp interview difference betwixt JSP include activeness together with include directive. Now nosotros know what does include directive agency together with when to utilisation include activeness or include directive.

Further Learning
Top xxx Unix Interview Questions answers

0 Response to "Difference Betwixt Include Directive Too Include Activeness Inwards Jsp Servlet"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel