Pass Parameters to other JSP Page (original) (raw)

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:

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

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

Java Code Geeks Snippets - Pass Parameters to other JSP Page
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>

Callee.jsp

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

Java Code Geeks Snippets - Pass Parameters to other JSP Page
This is the callee JSP page.

param1: <%= request.getParameter("param1") %>
param2: <%= request.getParameter("param2") %>

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.

Photo of Ilias Tsagklis

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

Back to top button