wood burning stoves 2.0*
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
Author

session scopt problem

Harshad Patel
Greenhorn

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. com.me.mybean - with simple set and get methods

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

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();
myb.setName("harshad");
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="com.my.LanguageBean">
<jsp:setProperty name="languageBean" property="*" />
</jsp:useBean>


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();
lb.setLanguage("superduper");
lb.setName("harshad");
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: http://aspose.com/file-tools
 
subject: session scopt problem
 
Similar Threads
Bean Scope??
Using bean declared in JSP from Servlet
jsp:useBean and TomCat's Introspection
sending updated array of javaBeans from JSP back to Servlet!
Servlet equivalent to <jsp:useBean ../>