File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JSP and the fly likes session scopt problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "session scopt problem" Watch "session scopt problem" New topic

session scopt problem

Harshad Patel

Joined: Jun 09, 2004
Posts: 5
Hi all
I am trying a simple example using session scope

I have a bean that stores customer information
e.g. - with simple set and get methods

I have some jsp pages which use the bean
<jsp:useBean id="languageBean" scope="request" class="">
<jsp:setProperty name="languageBean" property="*" />

Before the jsp's are used - the bean is intialised to some default values in the request object using the following code in a controller servlet

if (request.getAttribute("myBean")==null) {
System.out.println("my bean not in request yet ");
System.out.println("adding bean ");
MyBean myb = new MyBean();
System.out.println("adding bean");
request.setAttribute("myBean", myb);
else {
System.out.println("bean already in already in request");

The controller servlet then forwards the request on to the jsp page
which display the information using getProperty

using the request scope works fine, my bean can be accessed
On the first display of the jsp the default information is shown
on the next the updated infomatin is shown as expected

However when I try to use session scope I cant seem to update the information

I modified the code to use
<%@page session="true"%>
<jsp:useBean id="languageBean" scope="session" class="">
<jsp:setProperty name="languageBean" property="*" />

and the setup code in the controller servlet to use

HttpSession session = request.getSession();
if (session.getAttribute("languageBean")==null) {
System.out.println("no language bean in session yet ");
System.out.println("addind ");
LanguageBean lb = new LanguageBean();
System.out.println("adding beans");

session.setAttribute("languageBean", lb);

else {
System.out.println("language bean already in session");

Using the session scope
when the page is first displayed the bean is created and the default information is displyed ok using getProperty
However when I submit the message the Bean is not updated ?
Does any one have any ideas why I might be going wrong
I agree. Here's the link:
subject: session scopt problem
It's not a secret anymore!