Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

session scopt problem  RSS feed

Harshad Patel
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!