Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

setting list in session attribute  RSS feed

 
satish pankaj
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?
 
Ulf Dittmer
Rancher
Posts: 42970
73
  • 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.
 
Kumar Raja
Ranch Hand
Posts: 548
2
Hibernate Java Spring
  • 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
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65826
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • 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: 548
2
Hibernate Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you Bear
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!