This week's giveaway is in the Java/Jakarta EE forum.
We're giving away four copies of Java EE 8 High Performance and have Romain Manni-Bucau on-line!
See welcome thread
Win a copy of Java EE 8 High Performance this week in the Java/Jakarta EE forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

session scopt problem  RSS feed

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
Always! Wait. Never. Shut up. Look at this tiny ad.
ScroogeXHTML 7.2 - RTF to HTML5 / XHTML converter
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!