Example & Tutorial understanding programming in easy ways.

What is include directive in JSP?.

Include directive in JSP is used to import a static file or dynamic file e.g. JSP inside another JSP. Most common example of include directive is including header and footer in JSP. Include directive is also called file include because resource to be included is specified using file attribute as shown in below example of include directive:

Include directive is used to copy the content of one JSP page to another. Itís like including the code of one file into another.

Syntax of Include Directive:

<%@include file ="value"%>
here value is the JSP file name which needs to be included. If the file is in the same directory then just specify the file name otherwise complete URL(or path) needs to be mentioned in the value field.

Note: It can be used anywhere in the page:

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

The code written in rock.jsp will be included as it is in the jsp file which included it during JSP translation time and than merged code is get compiled to generate Servlet which is later used to server request. Include directive is also refereed as static import and it acts like #include from C or C++. file attribute is used specify resource to be included and can be specified in either relative url or absolute url. Since resource included using include directive is included during translation time and jsp doesn't compile if there is any change in included file. So include directive is not suitable to include dynamic resources because if included file changes between multiple request only old value is used always.

 

 

Read More →
Search
R4R Team
R4Rin Top Tutorials are Core Java,Hibernate ,Spring,Sturts.The content on R4R.in website is done by expert team not only with the help of books but along with the strong professional knowledge in all context like coding,designing, marketing,etc!