File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
parveiz khan
Greenhorn
Posts: 2
  • 0
  • 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?
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64192
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • 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
  • 0
  • 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?
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • 0
  • 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.
 
Vaib Gupta
Greenhorn
Posts: 15
  • 0
  • 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.
 
agnu sargar
Greenhorn
Posts: 9
  • 0
  • 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
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic