GTU WTAD Practical 26 : jsp page composite example

GTU WTAD Practical 26 :  Develop an application to write a “page-composite” JSP that includes other pages or passes control to another page.

GTU WTAD Practical 26

This JSP Program explains how to use jsp forward in the JSP Page and transfer control to another page. Here i have created red.jsp, green.jsp and blue.jsp page on the base of selection of option by user page will be displayed.

Jump to GTU WTAD Practical 27

File Name : index.jsp

File Location : Tomcat_Apache\webapps\gtu26\

<html>
	<head>
		<title>GTU WTAD Practical 26</title>
	</head>
	<body>
	
	<h2 align="center"> GTU WTAD Practical 26 :  Develop an application to write a "page-composite" JSP that includes other pages or passes control to another page.   </h2>
	<br><br><br>
	<form method="get" action="process.jsp">
		<b>Select Your Favorite Color :</b> 	<br><br>
		<input type="radio" name="color" value="red.jsp"> Red			<br>
		<input type="radio" name="color" value="green.jsp"> Green	<br>
		<input type="radio" name="color" value="blue.jsp"> Blue		<br><br>
		<input type="submit" value="Click Here">
	</form>
	<br><br><br><br><br><br>
	<jsp:include page="footer.jsp"/>
	</body>
</html>

 

File Name : process.jsp

File Location : Tomcat_Apache\webapps\gtu26\

<html>
<head>
	<title> GTU WTAD Practical 26 : Develop an application to write a "page-composite" JSP that includes other pages or passes control to another page.</title>
</head>
<body>

<%
	String c = request.getParameter("color");
	
	if(c==null)
	{
%>
		<jsp:forward page="./index.jsp"/>
<%	}
	else
	{
%>
		<jsp:forward page="<%=c%>"/>
<%
	}
%>
	
</body>
</html>

 

File Name : footer.jsp

File Location : Tomcat_Apache\webapps\gtu26\

<hr>
<h2 align="center">Designed and Developed by: Adarsh Patel (written inside footer.jsp page)</h2>

 

File Name : red.jsp

File Location : Tomcat_Apache\webapps\gtu26\

<html>
<body bgcolor="red">
<center>
<h2>Wow You Like Color of Blood !</h2>
<br><br><br>
<a href="index.jsp"> Back </a>
</center>
</body>
</html>

 

File Name : green.jsp

File Location : Tomcat_Apache\webapps\gtu26\

<html>
<body bgcolor="green">
<center>
<h2> You Like Green Color </h2>
<br><br><br>
<a href="index.jsp"> Back </a>
</center>
</body>
</html>

 

File Name : blue.jsp

File Location : Tomcat_Apache\webapps\gtu26\

<html>
<body bgcolor="blue">
<center>
<h2> Great !!! You Like Blue Color </h2>
<br><br><br>
<a href="index.jsp"> Back </a>
</center>
</body>
</html>

 

Output 1

GTU WTAD Practical 26

Output 2

GTU WTAD Practical 26

 

Output 3

GTU WTAD Practical 26

 

Output 4

GTU WTAD Practical 26

Leave a Reply