The document discusses two methods for including content from other resources in JSP pages:
The <%@ include %> directive copies the content of another file into the JSP source code during compilation. The <jsp:include> action dynamically includes the output of another page each time a request is made, allowing parameters to be passed. While <%@ include %> is faster at compilation and execution, <jsp:include> is more flexible as it allows the included page to be specified at runtime. The document also covers forwarding requests between pages using <jsp:forward>.
The document discusses two methods for including content from other resources in JSP pages:
The <%@ include %> directive copies the content of another file into the JSP source code during compilation. The <jsp:include> action dynamically includes the output of another page each time a request is made, allowing parameters to be passed. While <%@ include %> is faster at compilation and execution, <jsp:include> is more flexible as it allows the included page to be specified at runtime. The document also covers forwarding requests between pages using <jsp:forward>.
Copyright:
Attribution Non-Commercial (BY-NC)
Available Formats
Download as PPT, PDF, TXT or read online from Scribd
The document discusses two methods for including content from other resources in JSP pages:
The <%@ include %> directive copies the content of another file into the JSP source code during compilation. The <jsp:include> action dynamically includes the output of another page each time a request is made, allowing parameters to be passed. While <%@ include %> is faster at compilation and execution, <jsp:include> is more flexible as it allows the included page to be specified at runtime. The document also covers forwarding requests between pages using <jsp:forward>.
Copyright:
Attribution Non-Commercial (BY-NC)
Available Formats
Download as PPT, PDF, TXT or read online from Scribd
projects, having HTTP request handled by more than one server- side component is often desirable. Eliminating Redundancy Separating content and presentation Combining JSP and servlet technologies. Including other Resources The <%@include%> directive is used to copy static text into the JSP code before it is transformed into java servlet source code. The <jsp:include> action causes the servlet container to invoke other URL and merge its output with that of original JSP page. The include directive Absolute Path <%@ include file=“/includes/header.inc”%> Relative Path <%@ include file=“includes/header.inc” %> How it works When a <%@ include %> directive is encountered, the JSP container reads the specified file and merges its contents into JSP source code currently being parsed. The file name cannot be runtime expression. Included file must exist at compile time. Bad idea to use <%@ include %> directive The JSP 1.2 specification does not guarantee pages that include code in this manner will be noticed if code changes. This create maintenance problem. The included code uses the namespace of the including page, so you need to take care that no duplicate variable is here. Nobody but you have to find bugs. <jsp:include> Action In contrast to include directive, the jsp:include action is interpreted each time a request is made. S <jsp:include page=“resourcename” flush=“true”/> How It works The <jsp:include> action is parsed by JSP compiler, but rather than being executed at compilation time, it is converted into java code that invokes the named resource at request time. Restriction It has access to all implicit objects available to the calling JSP, including the response object. It can write to and flush the out object , but it cannot set response headers. Passing parameters to the included JSP
<jsp:include page=“pagename” flush=“true”>
<jsp:param name=“name_1” value=“value_1” /> <jsp:param name=“name_2” value=“Value_2” /> criteria <%@ include <jsp:include %> > Compilation slower Slightly faster time Execution Slightly faster slower time Flexibility Less page name is Pages can be fixed chosen at run time Forwarding Requests <jsp:forward page=“page1” />
Behavior of The JSP Engine. JSP Actions Consist of A Typical (XML-based) Prefix of "JSP" Followed by A Colon, Followed by The Action Name Followed by One or More Attribute Parameters