Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Passing Bean from JSP to Servlet  RSS feed

 
dharini ramakrishnan
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Kyle Brown
author
Ranch Hand
Posts: 3892
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!