• 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

Session Object values to Java Bean

 
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am creating an example online store, where the shopping cart is stored as a session object, and item beans are added to it each time a user adds an item to his cart.
If I want to access the session in a jsp, I can do

and then do operations such as

This is not a problem. However, I want to write these values to a database when the order is submitted but I don't know how to access the session object in a bean. I think what I want is the equivelent of "jsp:useBean", but am unsure how to do this.
I am using struts, so I need to access the session object, and iterate through each bean within it, adding their data to the DB.
Hope that's clear Any help would be much apprieciated
 
Ranch Hand
Posts: 442
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
your struts action will have a HttpServletRequest object, from which you can getSession(), this returns an HttpSession object, and you'll find all your customers details there.
PS next time you know what the JSP equivalent code is, and you need an answer ASAP, then simply check the JSP's code after it is translated into a servlet, you'll find the complete java source in there, not the best way to do things but hey, it will get you instant relief right
 
Ranch Hand
Posts: 405
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I believe that a javabean does not have implicit access to the servlet/jsp container i.e. session scope, request scope objects. So you may have to pass a session reference to the bean inorder to gain access to your session object.
But, my suggestion would be that you pass your cart


com.ops.entity.Order_Form


object to a worker bean which will act as a data access object to your database. The DAO will encapsulate your database functionality.
One such method would be:

The load method will iterate through each item saving it in the database.
Hope this helps.
cj
 
Yes, my master! Here is the tiny ad you asked for:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic