Win a copy of GANs in ActionE this week in the AI forum
or WebAssembly in Action in the JavaScript forum!
  • 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
  • Bear Bibeault
  • Paul Clapham
  • Jeanne Boyarsky
  • Knute Snortum
Sheriffs:
  • Liutauras Vilda
  • Tim Cooke
  • Junilu Lacar
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Joe Ess
  • salvin francis
  • fred rosenberger

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
  • 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?
 
Marshal
Posts: 67340
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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
  • 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
  • Mark post as helpful
  • send pies
  • 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
 
Are we home yet? Wait, did we forget the tiny ad?
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!