Example : How to pass single (static) value from one page another page using session .
<%----------------------- FirstPage.jsp ----------------------%>
<%--
Document : Session Sender Value Page
Created on : 14 Jul, 2019, 8:12:08 AM
Author : Codershelpline
--%>
<%@page contentType="text/html; charset=utf-8" language="java" errorPage=" "%>
<%
request.getSession().setAttribute("sidname1", "Welcome to U all in Your Site");
out.println("Session Start");
%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>First Session page</title>
</head>
<body>
<h1>Codershelpline</h1>
</body>
</html>
<%----------------------- SecondPage.jsp ----------------------%>
<%--
Document : Session Receiver Value Page
Created on : 14 Jul, 2019, 8:12:08 AM
Author : Codershelpline
--%>
<%@page contentType="text/html; charset=utf-8" language="java" errorPage=" "%>
<%
String SData=(String)session.getAttribute("sidname1");
out.println(SData);
%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>2nd Session page</title>
</head>
<body>
<h1>Codershelpline</h1>
</body>
</html>
Example : How to pass single (dynamic) value from one page another page using session .
<%----------------------- FirstPage.jsp ----------------------%>
<%--
Document : Session Sender Value Page
Created on : 14 Jul, 2019, 8:12:08 AM
Author : Codershelpline
--%>
<%@page contentType="text/html; charset=utf-8" language="java" errorPage=" "%>
<%
String UrTxtUname3=request.getParameter("UrTxtUname1");
String sub2=request.getParameter("sub");
try
{
if(sub2!=null)
{
if(sub2.equals("Submit"))
{
request.getSession().setAttribute("sidname1", UrTxtUname3);
out.println("Session Start");
}
}
}
catch(Exception e)
{
out.println(e);
}
%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>First Session page</title>
</head>
<body>
<body>
<form>
<center>
<fieldset style="width: 60%; background-color: aliceblue; border-radius: 8px; border-
width: 4px; border-color: cadetblue">
<table>
<h1>User Registration</h1><hr style="width: 90%">
<tr>
<td>User Name</td>
<td>:</td>
<td>
<input type="text" name="UrTxtUname1" id="UrTxtUname2" placeholder="Enter
User ID">
</td>
</tr>
<tr>
<td></td>
<td></td>
<td>
<input type="submit" name="sub" id="sub6" value="Submit">
<input type="reset" value="Reset">
</td>
</tr>
</table>
</fieldset>
</center>
</form>
</body>
</html>
<%----------------------- SecondPage.jsp ----------------------%>
<%--
Document : Session Receiver Value Page
Created on : 14 Jul, 2019, 8:12:08 AM
Author : Codershelpline
--%>
<%@page contentType="text/html; charset=utf-8" language="java" errorPage=" "%>
<%
String SData=(String)session.getAttribute("sidname1");
out.println(SData);
%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>2nd Session page</title>
</head>
<body>
<h1>Codershelpline</h1>
</body>
</html>
Example : How to pass multiple (static) values from one page another page using session .
<%----------------------- FirstPage.jsp ----------------------%>
<%--
Document : Session Sender Value Page
Created on : 14 Jul, 2019, 8:12:08 AM
Author : Codershelpline
--%>
<%@page contentType="text/html; charset=utf-8" language="java" errorPage=" "%>
<%
String arr[]={"Ram","Lion","12-05-2019"};
request.getSession().setAttribute("sidname1", arr);
out.println("Session Start");
%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>First Session page</title>
</head>
<body>
<h1>Codershelpline</h1>
</body>
</html>
<%----------------------- SecondPage.jsp ----------------------%>
<%--
Document : Session Receiver Value Page
Created on : 14 Jul, 2019, 8:12:08 AM
Author : Codershelpline
--%>
<%@page contentType="text/html; charset=utf-8" language="java" errorPage=" "%>
<%
String Multi_Data[]=(String[])session.getAttribute("sidname1");
out.println(" Received Session Values are: <br>");
for(int i=0; i<Multi_Data.length; i++)
{
out.println(Multi_Data[i]);
}
String UrTxtUname4="";
String UrPassPsd4="";
String UrDateDob4="";
out.println("<br><br> Received Session Values Through Variables are: <br>");
UrTxtUname4= Multi_Data[0];
out.println(UrTxtUname4);
UrPassPsd4=Multi_Data[1];
out.println(UrPassPsd4);
UrDateDob4=Multi_Data[2];
out.println(UrDateDob4);
%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>2nd Session page</title>
</head>
<body>
<h1>Codershelpline</h1>
</body>
</html>
Example : How to pass multiple (dynamic) values from one page another page using session .
<%----------------------- FirstPage.jsp ----------------------%>
<%--
Document : Session Sender Value Page
Created on : 14 Jul, 2019, 8:12:08 AM
Author : Codershelpline
--%>
<%@page contentType="text/html; charset=utf-8" language="java" errorPage=" "%>
<%
String UrTxtUname3=request.getParameter("UrTxtUname1");
String UrPassPsd3=request.getParameter("UrPassPsd1");
String UrDateDob3=request.getParameter("UrDateDob1");
String UrRdGender6=request.getParameter("UrRdbGender1");
String UrCmbMcode3=request.getParameter("UrCmbMcode1");
String UrNumMob3=request.getParameter("UrNumMob1");
String UrEmail3=request.getParameter("UrEmail1");
String UrChkMatric3=request.getParameter("UrChkMatric1");
String UrChkInter3=request.getParameter("UrChkInter1");
String UrTxrAdd3=request.getParameter("UrTxrAdd1");
String sub2=request.getParameter("sub");
try
{
if(sub2!=null)
{
if(sub2.equals("Submit"))
{
String x[]={UrTxtUname3,UrPassPsd3,UrDateDob3,UrRdGender6,UrCmbMcode3,UrNumMob3,
UrEmail3,UrChkMatric3,UrChkInter3,UrTxrAdd3};
request.getSession().setAttribute("sidname1", x);
out.println("Session Start");
}
}
}
catch(Exception e)
{
out.println(e);
}
%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Session first page</title>
</head>
<body>
<form><center>
<fieldset style="width: 60%; background-color: aliceblue; border-radius: 8px;
border-width: 4px; border-color: cadetblue">
<table>
<h1>User Registration</h1><hr style="width: 90%">
<tr>
<td>User Name</td>
<td>:</td>
<td>
<input type="text" name="UrTxtUname1" id="UrTxtUname2"
placeholder="Enter User ID">
</td>
</tr>
<tr>
<td>Password</td>
<td>:</td>
<td>
<input type="password" name="UrPassPsd1" id="UrPassPsd2"
placeholder="Enter Password">
</td>
</tr>
<tr>
<td>Date of Birth</td>
<td>:</td>
<td>
<input type="date" name="UrDateDob1" id="UrDateDob2" value="">
</td>
</tr>
<tr>
<td>Gender</td>
<td>: </td>
<td>
<input type="radio" name="UrRdbGender1" id="UrRdbGender2"
value="Male">Male
<input type="radio" name="UrRdbGender1" id="UrRdbGender3" value="Female"
>Female
</td>
</tr>
<tr>
<td>Mobile No. </td>
<td>:</td>
<td>
<select name="UrCmbMcode1" id="UrCmbMcode2">
<option value="+91">+91</option>
<option value="+92">+92</option>
<option value="+93">+93</option>
<option value="+94">+94</option>
</select>
<input type="number" name="UrNumMob1" id="UrNumMob2" placeholder="Enter
10 digit No.">
</td>
</tr>
<tr>
<td>E-mail</td>
<td>:</td>
<td>
<input type="Email" name="UrEmail1" id="UrEmail2" placeholder
="[email protected]">
</td>
</tr>
<tr>
<td>Qualification</td>
<td>:</td>
<td>
<input type="checkbox" name="UrChkMatric1" id="UrChkMatric2"
value="Matric" >Matric
<input type="checkbox" name="UrChkInter1" id="UrChkInter2" value="Inter"
>Intermediate
</td>
</tr>
<tr>
<td>Address</td>
<td>:</td>
<td>
<textarea name="UrTxrAdd1" id="UrTxrAdd2"></textarea>
</td>
</tr>
<tr>
<td></td><td></td>
<td>
<input type="submit" name="sub" id="sub6" value="Submit">
<input type="reset" value="Reset">
</td>
</tr>
</table>
</fieldset>
</center>
</form>
</body>
</html>
<%----------------------- SecondPage.jsp ----------------------%>
<%--
Document : Session Receiver Value Page
Created on : 14 Jul, 2019, 8:12:08 AM
Author : Codershelpline
--%>
<%@page contentType="text/html; charset=utf-8" language="java" errorPage=" "%>
<!DOCTYPE html>
<%
String UrTxtUname4="";
String UrPassPsd4="";
String UrDateDob4="";
String UrRdGender7="";
String Gender1="";
String Gender2="";
String UrCmbMcode4="";
String Cmb1="";
String Cmb2="";
String UrNumMob4="";
String UrEmail4="";
String UrChkMatric4="";
String Check1="";
String UrChkInter4="";
String Check2="";
String UrTxrAdd4="";
String y[]=(String[])session.getAttribute("sidname1");
UrTxtUname4= y[0];
UrPassPsd4=y[1];
UrDateDob4=y[2];
UrRdGender7=y[3];
if(UrRdGender7.equals("Male"))
{
Gender1="checked";
}
if(UrRdGender7.equals("Female"))
{
Gender2="checked";
}
UrCmbMcode4=y[4];
if(UrCmbMcode4.equals("+91"))
{
Cmb1="checked";
}
if(UrCmbMcode4.equals("+92"))
{
Cmb2="checked";
}
UrNumMob4=y[5];
UrEmail4=y[6];
UrChkMatric4=y[7];
if(UrChkMatric4.equals("Matric"))
{
Check1="checked";
}
UrChkInter4=y[8];
if(UrChkInter4.equals("Inter"))
{
Check2="checked";
}
UrTxrAdd4=y[9];
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>session 2nd page</title>
</head>
<body>
<form><center>
<fieldset style="width: 60%; background-color: aliceblue; border-radius: 8px; border-
width: 4px; border-color: cadetblue">
<table>
<h1>User Registration</h1><hr style="width: 90%">
<tr>
<td>User Name</td>
<td>:</td>
<td>
<input type="text" name="UrTxtUname1" id="UrTxtUname2" value="
<%=UrTxtUname4%>">
</td>
</tr>
<tr>
<td>Password</td>
<td>:</td>
<td>
<input type="password" name="UrPassPsd1" id="UrPassPsd2" value="
<%=UrPassPsd4%>">
</td>
</tr>
<tr>
<td>Date of Birth</td>
<td>:</td>
<td>
<input type="date" name="UrDateDob1" id="UrDateDob2" value="
<%=UrDateDob4%>">
</td>
</tr>
<tr>
<td>Gender</td>
<td>: </td>
<td>
<input type="radio" name="UrRdbGender1" id="UrRdbGender2" value="Male"
<%=Gender1%>>Male
<input type="radio" name="UrRdbGender1" id="UrRdbGender3" value="Female"
<%=Gender2%> >Female
</td>
</tr>
<tr>
<td>Mobile No. </td>
<td>:</td>
<td>
<select name="UrCmbMcode1" id="UrCmbMcode2" >
<option value="+91"<%=Cmb1%>>+91</option>
<option value="+92"<%=Cmb2%>>+92</option>
</select>
<input type="number" name="UrNumMob1" id="UrNumMob2" value="
<%=UrNumMob4%>">
</td>
</tr>
<tr>
<td>E-mail</td>
<td>:</td>
<td>
<input type="Email" name="UrEmail1" id="UrEmail2" value="<%=UrEmail4%>">
</td>
</tr>
<tr>
<td>Qualification</td>
<td>:</td>
<td>
<input type="checkbox" name="UrChkMatric1" id="UrChkMatric2"
value="Matric" <%=Check1%> >Matric
<input type="checkbox" name="UrChkInter1" id="UrChkInter2" value="Inter"
<%=Check2%>>Intermediate
</td>
</tr>
<tr>
<td>Address</td>
<td>:</td>
<td>
<textarea name="UrTxrAdd1" id="UrTxrAdd2"><%=UrTxrAdd4%></textarea>
</td>
</tr>
</table>
</fieldset>
</center>
</form>
</body>
</html>
0 Comments