• 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
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Accessing javabeans values in servlet

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi..
can i access the jaav bean fields in a servlet?
I am making an application that have one bean,2 servlet n 2 jsps..
the architecture goes like this:
JSP calls sevlet which makes beans and forward them to another JSP.
On this second jsp the user selects the data to be store in db and click save button..now when this save button is clicked JSP transfer control to another servlet which have to save data in db.
Now the problem is that i do not know how to get the data that was shown in jsp via bean's getProperty method.
plz help.
 
Ranch Hand
Posts: 327
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You could do any of the following to get access to the bean's info in your servlet:

1) Store the bean in session scope and get it in the servlet with



2) Store the bean state in form fields in the jsp and then submit the form to the servlet and get the data out of the request like so

The problem with this method is that it makes you "Stringify" all of your bean state

3) Make a link in your jsp page that has the beans data as request parameters like so

This method also requires you to "Stringify" your bean state
[ December 08, 2004: Message edited by: Anthony Watson ]
 
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Anthony Watson:
Store the bean in session scope and get it in the servlet with



Don't forget that you can store the bean in scopes other than session. If your bean has application scope, you'll need to get it from the ServletContext. For example:

YourClass yourClassInstance = (YourClass)getServletContext().getAttribute("yourBeanInstance");
 
Any sufficiently advanced technology will be used as a cat toy. And this tiny ad contains a very small cat:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic