• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

Setting parameters with jsp:setProperty

 
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Ranch Hand
Posts: 5575
Eclipse IDE Windows XP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Sheriff
Posts: 67750
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
If tomatoes are a fruit, then ketchup must be a jam. Taste this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic