• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

"jsp:usebean" question

 
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I define a bean in first.jsp using "jsp:usebean" with "scope=session" and populate all fields in bean. I then forward to second.jsp which makes no reference to bean created in first.jsp. Then second.jsp forwards to third.jsp, which has "jsp:usebean" defined for the bean created in first.jsp.

I lost all of the values which were populated from first.jsp. I thought that as long as I was in same session the bean will retain all values regardless of where I go.

first.jsp:
<jsp:useBean id="mauMainForm" class="com.att.vtone.mau.MauMainForm" scope="session" >
<jsp:setProperty name="mauMainForm" property="*"/>
</jsp:useBean>

second.jsp: none

third.jsp:
<jsp:useBean id="mauMainForm" class="com.att.vtone.mau.MauMainForm" scope="session" >

</jsp:useBean>

Question: Do I need to define the bean in every jsp in order to retain the values in the bean?
 
Bartender
Posts: 4179
22
IntelliJ IDE Python Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No you don't need to define it in every page. As long as your session is maintained then the code you have should work. Things to check:
1) Spelling
2) Spelling
3) Spelling ;-)
4) Is your session being maintained?

To test, you can do:

You should get true just once for the first output line and false the rest of the time, and the same id number for all requests.

If you don't then you have to ask yourself why aren't my sessions being maintained. The most probably reason would be that your client doesn't have cookies enabled. By default, sessions are maintained by cookies so if your client has cookies turned off, then the session will be lost every response cycle. You should use URL Re-writing to prevent that. But there are other reasons which only your environment could tell you.

If your session is being maintained but you still don't get to keep the object then you need to test a few other things. Is the object successfully being created? Check your log files for errors. Is it being removed? Look around your code base to see if there is some line of code that sets the same value to null or empties session attributes.

Another thing to double check is what do you actually mean by 'not retaining values'. Does the bean get re-created in page 3 or do the values that get stored in page 1 get lost? Check this by first making sure that the values you set on page 1 are actually set the way you think they should be (ie print them out). Then on page 3 change the jsp:useBean tag to:

This will force the JSP to use a previously stored mauMainForm, not create a new one. If the one you created in page 1 still exists, it will be used, if not you get an error. The error will make it clear that the object you created in page 1 is lost, so you can narrow your search to how that happens. If no error occurs then you know the values were not stored properly or were later erased, so you can, again, narrow your search for what it wrong.
 
Don Martino
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Steve!

Spelling!
Spelling!
Spelling!

You were correct, spelling was wrong. Made correction and it works!!
 
Willie Smits can speak 40 languages. This tiny ad can speak only one:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic