my dog learned polymorphism*
The moose likes JSP and the fly likes proper way to insert a record to database using javabean -servlet or jsp? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "proper way to insert a record to database using javabean -servlet or jsp?" Watch "proper way to insert a record to database using javabean -servlet or jsp?" New topic
Author

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

Peter Maxwell
Greenhorn

Joined: Jun 14, 2009
Posts: 14
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

Joined: Jan 10, 2002
Posts: 60764
    
  65

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.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Peter Maxwell
Greenhorn

Joined: Jun 14, 2009
Posts: 14
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

Joined: Jan 10, 2002
Posts: 60764
    
  65

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

Joined: Jun 14, 2009
Posts: 14
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: proper way to insert a record to database using javabean -servlet or jsp?
 
Similar Threads
Dynamic form table generation and naming of form fields
Variable value attribute in jsp:setProperty
Knowning which link was clicked (take 2)
How to use dynamically value by using <jsp:useBean> tag?
making my bean accesible to 3rd JSP using request scope