Download as ppt, pdf, or txt
Download as ppt, pdf, or txt
You are on page 1of 13

Request Dispatching

 In large scale development


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” />

You might also like