Home » Enterprise Java » jsp » Pass Parameters to other JSP Page

About Ilias Tsagklis

Ilias Tsagklis
Ilias is a software developer turned online entrepreneur. He is co-founder and Executive Editor at Java Code Geeks.

Pass Parameters to other JSP Page

This is an example of how to pass parameters from one JSP page to another. JavaServer Pages (JSP) is a server-side programming technology that enables the creation of dynamic, platform-independent method for building Web-based applications. JSP have access to the entire family of Java APIs, including the JDBC API to access enterprise databases. In order to pass parameters from one JSP page to another we have created two JSP pages, as shown below:

  • Caller.jsp uses the jsp:include action, that includes the page Callee.jsp at the time the page is requested. It uses the jsp:param property inside the jsp:include tag to set values to one or more parameters passed to the other page.
  • Callee.jsp page uses the request object that is an instance of a javax.servlet.http.HttpServletRequest object. Each time a client requests a page the JSP engine creates a new object to represent that request. The request object provides methods to get HTTP header information including form data, cookies, HTTP methods. Using the getParameter(String name) it gets the value of a request parameter as a String, here is gets the value of the parameter passed to is by Caller.jsp.

Let’s take a look at the code snippet that follows:  
Caller.jsp

<%@ page language="java" contentType="text/html;charset=UTF-8" %>

<html>

<head>
	<title>Java Code Geeks Snippets - Pass Parameters to other JSP Page</title>
</head>

<body>

	This is the caller JSP page.
	
	<jsp:include page="Callee.jsp">
	    <jsp:param name="param1" value="value1"/>
	    <jsp:param name="param2" value="value2"/>
	</jsp:include>

</body>

Callee.jsp

<%@ page language="java" contentType="text/html;charset=UTF-8" %>

<html>

<head>
	<title>Java Code Geeks Snippets - Pass Parameters to other JSP Page</title>
</head>

<body>

	This is the callee JSP page.
	
	param1: <%= request.getParameter("param1") %>
	param2: <%= request.getParameter("param2") %>

</body>

URL:

http://myhost:8080/jcgsnippets/Caller.jsp

Output:

This is the caller JSP page. This is the callee JSP page. param1: value1 param2: value2

  
This was an example of how to pass parameters from one JSP page to another in Java.

(+1 rating, 1 votes)
1 Comment Views Tweet it!

Do you want to know how to develop your skillset to become a Java Rockstar?

Subscribe to our newsletter to start Rocking right now!

To get you started we give you our best selling eBooks for FREE!

 

1. JPA Mini Book

2. JVM Troubleshooting Guide

3. JUnit Tutorial for Unit Testing

4. Java Annotations Tutorial

5. Java Interview Questions

6. Spring Interview Questions

7. Android UI Design

 

and many more ....

 

Receive Java & Developer job alerts in your Area

 

1
Leave a Reply

avatar
1 Comment threads
0 Thread replies
0 Followers
 
Most reacted comment
Hottest comment thread
1 Comment authors
John Recent comment authors
  Subscribe  
newest oldest most voted
Notify of
John
Guest
John

I have common jsp(Ex: test.jsp which has a common code snippet) which is included in all the remaining jsps(Ex Exam1.jsp, Exam2.jsp …..), so how can i pass the objects from Exam1.jsp to test.jsp and Exam2.jsp to test.jsp.