- <jsp:include>
- <jsp:forward>
- <jsp:param>
- <jsp:plugin>
We now look at them one by one.
i. The <jsp:include> Tag
This jsp:include tag allows inclusion of the content of the given file within the
JSP page at the request time. Notice that it is different from the include directive
we studied above where the content of the file was included at translation time. It's
syntax is as follows :
<jsp:include page="pathToFile" flush="true | false" />
The page attribute contains the path to the given file you want to include ( which
can be a JSP page, Servlet or a simple HTML/text file ). Flush attribute should be
set to true for compatibility with JSP 1.1. In JSP 1.2 compatible application servers
( e.g, Tomcat 4.0 ) you can set the flush attribute to false.
ii. The <jsp:param> Tag
This tag is used inside the <jsp:include>, <jsp:forward> and <jsp:plugin>
tags. It defines and sets different parameters with their values .e.g,
<jsp:include page="file.jsp" flush="true" %>
<jsp:param name="name" value="Faisal Khan" />
</jsp:include>
In the code above a parameter with the name 'name' and a value of "Faisal Khan"
has been provided to the included JSP page; file.jsp. The file.jsp page can access the
value of this paramter by :
<%
String name = request.getParamter("name");
%>
iii. The <jsp:forward> Tag
This tag allows you to forward the control to a given page. It's syntax is as follows :
<jsp:forward page="pathToFile" />
Where pathToFile is the path to the page you want control to be forwarded to. Like
<jsp:include> tag you can also use <jsp:param> to provide parameters to the
forwarded page.
iv. The <jsp:plugin> Tag
This tag allows you to embed Java applets or beans in a web page. It's syntax is as follows :
<jsp:plugin type="bean | applet" code="className"
codebase="path to root directory containing classes"
align="top | middle | bottom | left | right"
archives="jar files required for this app"
height="height in pixels" width="width in pixels"
hspace="horizontal space in pixels" vspace="vertical space"
jreversion="the JRE version required"
name="name of object"
nspluginurl="URL for Netscape plugin"
iepluginurl="URL For IE plugin"
>
<jsp:params>
<jsp:param name="name" value="value" />
</jsp:params>
<jsp:fallback>
Sorry your browser doesn't support Java applets.
</jsp:fallback>
</jsp:plugin>
Almost all the attributes for the <jsp:plugin> tag above are self explanatory.
Java Bean Tags
There is one other small group of tags which allow the incorporation of Java beans
in a JSP page. We will look Java beans and bean tags in detail in some other article
as this topic deserves some more attention.
Summary
In this article we briefly had a look at all of the different elements which constitute
a JSP page. We first learned about three types of directives and then moved forward to
learn about four types of scripting elements. In the end we discussed what are built-in
JSP tags which are provided to us as part of the JSP specification.
Two things that we didn't discuss were :
I deliberately left the above two topics because they deserve more attention and
don't worry we will be giving them due attention in my next articles.
This article provides a strong foundation for future JSP articles and once you have
understood these simple JSP elements, you can move forward to learn about Java
beans, custom tags, JDBC, XML and frameworks for web application architectures.