Site icon NgDeveloper

Pass values from one jsp to another jsp file

pass-values-from-one-jsp-to-another-jsp-file-featured
pass-values-from-one-jsp-to-another-jsp-file-blog

Pass values from one jsp to another jsp file:

Form values from one jsp can be sent to another jsp file with action parameter in form and getParameter method in the second jsp file.

 

Things to remember:

jsp1.jsp file:

<%@ 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>First JSP Page</title>
		</head>
		<body>
Enter your Name here:
			<form action="jsp2.jsp" method="POST">
				<input type="text" name="name" id="name"/>
				<input type="submit" value="Pass Name to Jsp2.jsp"/>
			</form>
		</body>
</html>

jsp2.jsp file:

<%@ 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>Second JSP Page</title>
		</head>
		<body>
			<%
String enteredName = request.getParameter("name");
out.println(enteredName);
%>
			</body>
</html>

 
Output:

jsp2.jsp prints values whichever jsp1.jsp sends:

Download Source Code for jsp to jsp value passing working project

Exit mobile version