pageConext.getAttribute() return null value
843838Mar 23 2006 — edited Mar 24 2006Hi All,
I have two JSPs sample.jsp & yourjspname.jsp.
In Sample.jsp I'm trying to set an attribute in the pageContext(session scope), which I'm retrieving in the yourjspname.jsp. But its returning a null value. Can some help. Below is the code for sample.jsp & yourjspname.jsp.
sample.jsp code
------------------------------------------
<html>
<head>
</head>
<body>
<form name="yourformname" action="yourjspname.jsp" action="POST">
<input type="text" name="myText" value="lalitha">
<input type="submit" name="mySubmit" value="Go">
<input type="hidden" name="name">
<input type="hidden" name="phoneNum">
</form>
The class that instantiated this JSP is
<%
String myText = request.getParameter("myText");
pageContext.setAttribute("myText", myText, PageContext.SESSION_SCOPE);
%>
</form>
</body>
</html>
yourjspname.jsp code
--------------------------------------
<%@ page contentType="text/html;charset=windows-1252"%>
<%@ page import="java.lang.*" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>untitled</title>
</head>
<body>
<P>Hello this is your jsp...........................</P>
<P> </P>
<%
String myText = (String)pageContext.getAttribute("myText", PageContext.SESSION_SCOPE );
System.out.println("------------------> " + myText);
%>
</body>
</html>