• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

setting list in session attribute

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
dear users,
i have a problem in my servlet class..i am getting data from database and storing that into list..and on the basis of list is empty i am setting session attribute
and then retriving in jsp page through codes..at the time of execution when i am first selecting the category as 'java' it is giving results and again when i am selecting category as 'asp' and then it is giving no books found..but it also carry previous data of 'java'...

i am pasting my code ...
please kindly help me to understand code...

searchbook.jsp



searbookservlet.java (url:searchbook.jlc)



showbook.jsp



my question is why it is carrying results?
 
Rancher
Posts: 43081
77
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to JavaRanch. "BOOKS" should be a request attribute, not a session attribute.

You should not override the service method, by the way. Decide whether you want to override doGet or doPost; in this case, it would have to be doPost, because you're using a POST in searchbook.jsp.
 
Ranch Hand
Posts: 558
2
Hibernate Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Ulf,

What could be the issue in storing as a session attribute. The whole Request/Response is happening anyway in the same session, I believe.

Thanks
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If the scoped variable ("attribute") only needs to be used for the current request, storing in the session is needless and poor practice. It needs extra code to clean it out (or it'll just continue to waste space until the session is reclaimed). Never use session scope when request scope is more appropriate.
 
Kumar Raja
Ranch Hand
Posts: 558
2
Hibernate Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you Bear
 
I would challenge you to a battle of wits, but I see you are unarmed - shakespear. Unarmed tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic