JSP include Action

JSP include Action


Posted in : Java Posted on : January 24, 2012 at 6:54 PM Comments : [ 0 ]

In this tutorial you will learn how to use the 'include' action in a JSP file.

JSP include Action

In this tutorial you will learn how to use the 'include' action in a JSP file.

include action in JSP is used to include resource in JSP file these resource can be either static or dynamic. Elements of this action is processed at the time of the JSP page execution. Here in case of the static resource contents are inserted into the calling JSP file and in case of dynamic resource first the included resource receives the request and executed and produce the result and then this result is included in the calling JSP file.

Syntax :

<jsp:include page="includedPage" />

Example :

includeAction.jsp

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Jsp include Action Example</title>
</head>
<body>
Enter the last number till you want to print :
<jsp:include page="includeToIncludeAction.jsp"/>
</body>
</html>

HTML file that is to be included into the above jsp file.

includeToIncludeAction.jsp

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<form>
<input type="text" name="text" />
<input type="submit" value="submit" />
</form>
<%! int num; %>
<%
if (request.getParameter("text") != null)
{
num = Integer.parseInt(request.getParameter("text"));
}
%>
<table>
<tr><td>Number</td></tr>
<%
for (int i = 1; i < num+1; i++)
{
%>
<tr>
<td align="right"><%=i %></td>
</tr>
<%
}
%>

</table>

Output :

When you will execute the includeAction.jsp output will be as following :

1.

 

2.

3.

Download Source Code

Go to Topic «PreviousHomeNext»

Your Comment:


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 

 
Tutorial Topics