This week's book giveaway is in the Other Languages forum.
We're giving away four copies of Functional Reactive Programming and have Stephen Blackheath and Anthony Jones on-line!
See this thread for details.
Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

proper way to insert a record to database using javabean -servlet or jsp?

 
Peter Maxwell
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello everybody,
I need to insert a record into a table. I do the following currently,
1)Get the values of input fields from the form of jsp(say, A)
2)Submit them to another jsp(say, B)
3)In jsp B, i use the jsp:useBean and jsp:setProperty to send the values to a bean.
4)Now I forward from jsp B, to a servlet C.
5)This servlet receives the bean and uses an ordinary java class which creates connections and
insert the members of the bean to a table in database.

Is the above correct way to do this?.
Some one here pointed out that submit to a jsp is not a proper way to go in another thread.
Does all the steps above are necessary to insert a record to a database?
Can i use a servlet instead of a jsp in step 2? Is there any equivalent for jsp:useBean and jsp:setProperty in servlets?
Any good alternatives there?
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65227
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It is not proper. As pointed out, submitting to a JSP just so you can use the old-fashioned setProperties tag is just awkward.

Submit to a servlet and grab the values from the request and set them into the bean in Java code. if you would like "bean assist", check out the Jakarta commons BeanUtils project.
 
Peter Maxwell
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:It is not proper. As pointed out, submitting to a JSP just so you can use the old-fashioned setProperties tag is just awkward.

Submit to a servlet and grab the values from the request and set them into the bean in Java code. if you would like "bean assist", check out the Jakarta commons BeanUtils project.


Thanks for replying Bear Bibeault.
I checked the commons BeanUtils project.
The setProperty method provides a way to set the properties of the one by one. But the setProperty tag allows to set all the properties at one go using attribute property="*" .
Is there any method which allows me to do the same?. Or is it the case of tradeoff between convenience of developer vs maintainability?
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65227
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Even if it weren't the case, again, using a JSP to collect the data and then forward to a servlet is just bizarre.

In any case, check out BeanUtils.populate() to get the same effect.
 
Peter Maxwell
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:Even if it weren't the case, again, using a JSP to collect the data and then forward to a servlet is just bizarre.

In any case, check out BeanUtils.populate() to get the same effect.


Thanks, I'll check that out and post back if i am stuck.
Thanks again for your time.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic