File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSP and the fly likes how to get the values in a servlet? the values are set in a bean using jsp Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "how to get the values in a servlet? the values are set in a bean using jsp" Watch "how to get the values in a servlet? the values are set in a bean using jsp" New topic
Author

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

parveiz khan
Greenhorn

Joined: Nov 22, 2009
Posts: 2
<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

Joined: Jan 10, 2002
Posts: 61415
    
  67

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.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
parveiz khan
Greenhorn

Joined: Nov 22, 2009
Posts: 2
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

Joined: Sep 29, 2008
Posts: 12617

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

Joined: May 11, 2009
Posts: 15
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

Joined: Feb 01, 2008
Posts: 9
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
 
subject: how to get the values in a servlet? the values are set in a bean using jsp