Forums Register Login

Passing Bean from JSP to Servlet

+Pie Number of slices to send: Send
I have a bean Candidate that I want to pass from a jsp to a servlet.
I have the following code in my JSP:
<jsp:useBean id="Candidate" class="com.logicinfo.beans.Candidate" scope="session" />
<jsp:setProperty name="Candidate" property="*" />
I have a text field called 'name' in my form.
I have the following code in my servlet:
HttpSession session = request.getSession();
candidate = (Candidate) session.getAttribute("Candidate");
Then I try to retrieve a property from my bean and it returns no value.
What am i doing wrong??
Any help is appreciated.
+Pie Number of slices to send: Send
Are you certain you are POSTing to the JSP?
BTW -- personally, I abhor doing this kind of thing. IMHO the setProperty() tag is an abomination. Instead, consider building your systems with what is called a Model-II architecture, which is where all POSTS and GETS call Servlets, which then do forward() or include() to a JSP. In your servlet method you would do all of the appropriate object creation, parsing, etc. Check out Struts, for instance, from http://jakarta.apache.org/struts
------------------
Kyle Brown,
Author of Enterprise Java (tm) Programming with IBM Websphere
+Pie Number of slices to send: Send
Model-II (MVC) is the only way to go. (well, there are others, but if it ain't broke...)
The only thing I'd add to Kyle's post is that (although I don't use beans) personally I wouldn't mix the bean tag and code methods of handling data, I'd stick to only using <jsp:usebean ... or session.getAttribute...
Dave.
Enjoy the full beauty of the english language. Embedded in this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 998 times.
Similar Threads
simple use bean questions
Extracting data from a bean
Problem passing params using managed-propertys
Hibernate error with Spring MVC
Unable to Redirect to the On submitting a form
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 11:51:52.