Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

pageConext.getAttribute() return null value

843838Mar 23 2006 — edited Mar 24 2006
Hi 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>&nbsp;</P>
<%

String myText = (String)pageContext.getAttribute("myText", PageContext.SESSION_SCOPE );
System.out.println("------------------> " + myText);

%>
</body>
</html>
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Apr 21 2006
Added on Mar 23 2006
11 comments
406 views