• Post Reply Bookmark Topic Watch Topic
  • New Topic

Passing object with <SELECT>

 
Kees deVries
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So, in a from i let the user choose a product. (The complete form is adding a new order)


It will post to a servlet. In the service I have this method:

because I want the product object to be given to the method.

How does this work with the JSP and the servlet? (choosing the object from the list and passing it through the servlet)
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 35730
412
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Kees,
Does your product have a key/id number? If so, you should add that as the option's value in your JSP. Then the servlet can read that key to look up the actual product object (from a database/list/where ever you store it.) You can use the same approach with a product name if the name is guaranteed to be unique.
 
Kees deVries
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes Product has an ID.
So it would something like:

right?
And how would that fit into the servlet?

For general strings I would do a request.getParameter. How does this work with the ID/objects?
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65530
108
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
All parameters are passed as as strings; that's just the way HTTP works. So in the case of numerics, you'd need to convert it.

Passing objects makes no sense*.






* I have seen people serialize objects to JSON for passing, but that's not an approach I'd recommend as it has numerous problems. Pass id values and fetch objects from the model.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!