• 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

how to get the values in a servlet? the values are set in a bean using jsp

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
<jsp:useBean id="bean" class="com.hrms.servlet.UserBean" scope="session" >
<jsp:setProperty name="bean" property="username" param="textfield1" />
<jsp:setProperty name="bean" property="password" param="textfield2" />
</jsp:useBean>

what should i write in servlet to retrieve those values?
 
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
What is the relationship of the servlet to the JSP?

Assuming that the servlet is submitted to by the HTML page generated from the JSP, then the only way to send data to the servlet over HTTP is as request parameters; either in the query string or as form elements.

Or, take the direct (server-only) approach and place the values in the session for later retrieval.
 
parveiz khan
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
yes. the jsp is submitted to a servlet.

i did not understand completely.

my assumption is if i set some properties in a bean (from jsp) those values i can retrieve in the servlet from that bean. but how? i dont know how to write the code.
or is my assumption is wrong?
 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm not clear on why you'd want to instantiate a bean in a JSP, set its values, then retrieve it in the servlet.

Why not just create the bean in the servlet that displays the original JSP? Or if you *are* submitting a form, put the values into the form.
 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please correct me if I have not understood your problem. You want to access 'bean' in your servlet. Isn't 'bean' set as a session attribute when you specify

<jsp:useBean id="bean" class="com.hrms.servlet.UserBean" scope="session" >

I think you can directly access this attribute using getAttribute() method.
 
Greenhorn
Posts: 9
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i think you can make object of bean class in servlet and by properly casting you can get all the values in servelt
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic