Passing values from one jsp to another jsp

Step 1: source.jsp

 

[html]<%@ 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>Insert title here</title>
</head>
<body>
<form method="post" action="destination.jsp">
My Favourite Colors are
First Value <input type="text" name="tf1">
Second Value <input type="text" name="tf2">
Third Value <input type="text" name="tf3">
<input type="submit" value="add">
</form>
</body>
</html>[/html]

 

Step 2: destination.jsp

 

[html]<%@ 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>Insert title here</title>
</head>

<body>
<%– <%String[] getting = request.getParameterValues("cb1");
for(int i=0;i<getting.length;i++){
out.println(getting[i]);
}
System.out.println(getting);

%> –%>

<%
int value1 = Integer.parseInt(request.getParameter("tf1"));
int value2 = Integer.parseInt(request.getParameter("tf2"));
int value3 = Integer.parseInt(request.getParameter("tf3"));
int total = value1+value2+value3;
out.println("Total is "+total);
%>

</body>
</html>[/html]

 

Output: source.jsp

source jsp

destination.jsp

destination jsp output

 

Thanks for reading this post………….!!!

 

 

Leave a Reply