Friday, July 22, 2016

Pass parameters from one JSP to another JSP

To do this, you need to add jsp:include and its jsp:param properties .

First.jsp
<%@ page language="java" contentType="text/html;charset=UTF-8" %>
<html>
<head>
    <title>Pass Parameters from one JSP to another JSP Page</title>
</head>

<body>
      This is your First JSP page.

    <jsp:include page="Second.jsp">
        <jsp:param name="param1" value="Firstvalue"/>
        <jsp:param name="param2" value="Secondvalue"/>
    </jsp:include>
</body>
</html>

Second.jsp
<%@ page language="java" contentType="text/html;charset=UTF-8" %>
<html>
<head>
    <title>Pass Parameters Example</title>
</head>

<body>
    This is your second JSP page.
    param1: <%= request.getParameter("param1") %>
    param2: <%= request.getParameter("param2") %>
</body>
</html>

Explanation :

1.You have to include Sceond.jsp in the First.jsp page.

2. Use jsp:include property, jsp:param to pass parameter to the Second.jsp which was already included with the help of jsp:include.

3.Retrieve the passed values from First.jsp through getParameter method.

No comments:

Post a Comment