• Post Reply Bookmark Topic Watch Topic
  • New Topic

Setting parameters with jsp:setProperty

 
Jim Petersson
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
I'm using a jsp page with some inputfields. These fields map to fields in a java-bean. What I want to do is have the user enter text in some inputfields, map it to my javabean, and then do a post to a servlet. In the servlet I want to get my bean from the session, and print out its fields (That should have been set by the jsp-page)
My code looks something like this:

JSP:


Servlet (doPost):


What happens is that I can get the Customer object from the session (in my servlet), but the name and number fields are null.

Any suggestions on what I'm doing wrong here?

[ October 28, 2008: Message edited by: Jim Petersson ]
[ October 28, 2008: Message edited by: Jim Petersson ]
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Jim Petersson:
I'm using a jsp page with some inputfields. These fields map to fields in a java-bean. What I want to do is have the user enter text in some inputfields, map it to my javabean, and then do a post to a servlet. In the servlet I want to get my bean from the session, and print out its fields (That should have been set by the jsp-page)
My code looks something like this:



well, you have servlet and java bean class so,in this situation why you need jsp:useBean?

Even though, the way of you are using the jsp:useBean is wrong.Here how your jsp:useBean will get your param value?
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65524
105
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're doing it backwards.

You are trying to set the bean properties before the form is even being sent to the browser. So how can it fill in fields that don't even exist yet?

Moreover, the type of use you are trying to make of useBean and setProperty is an old-fashioned hold-over from days gone by. These days, it's considered a poor practice to submit a form to a JSP. Rather, the servlet should retrieve the parameters (or delegate this responsibility) to fill in the bean rather than letting a JSP do it.
[ October 28, 2008: Message edited by: Bear Bibeault ]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!