• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Knute Snortum
  • Bear Bibeault
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Tim Holloway

setting list in session attribute

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • 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: 43009
76
  • Likes 1
  • Mark post as helpful
  • send pies
  • 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
  • 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: 67269
170
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
Thank you Bear
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!