A simple Web-Application demonstrating how to include one jsp page into another jsp.
CodeProject
1. Create a JSP : index.jsp
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20. |
<%@ 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>Login Page !!!!</title>
</head>
<body>
<h1></h1>
<jsp:include page="/welcome.jsp">
<jsp:param name="firstName" value="Enter First Name" />
<jsp:param name="lastName" value="Enter Last Name" />
</jsp:include>
<hr>
<h2>welcome.jsp page gets included along with parameters</h2>
</body>
</html>
|
|
2. Create a JSP : welcome.jsp
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25. |
<%@ 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>A User Input Page !!!</title>
</head>
<body bgcolor="#ADB1A9">
<form method="POST" action="xxx.jsp">
First Name : <input type="text" id="firstName"
value='<%=request.getParameter("firstName")%>' /><br>
Last Name : <input type="text" id="lastName"
value='<%=request.getParameter("lastName")%>' /><br> <br>
<input type="submit" value="Submit" />
</form>
</body>
</html>
|
|
Output of the program :
As soon as user request for index.jsp page, the request goes to index.jsp and there it finds that it has included a page welcome.jsp by the use of jsp:include tag along with the necessary parameters with it. The control internally brings welcome.jsp to index.jsp and the rendered page of welcome.jsp is visible at the browser.