Win a copy of Practice Tests for OCP Java 17 Certification Exam (1Z0-829) this week in the OCPJP forum!
  • 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 ...
  • Tim Cooke
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Liutauras Vilda
  • Rob Spoor
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
  • Scott Selikoff
  • Piet Souris
  • Jj Roberts
  • fred rosenberger

doing database updates in struts

Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can anybody suggest the best method to do database updates using struts. I guess we need to have a updateaction servlet.
I need somebody to kindly put me in the right direction.
Ranch Hand
Posts: 287
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Struts doesn't really have a way to directly update a database.
Probably the easiest way to do it is from the Action class of the page you're trying to update.
Assuming you have all the mapping correct in the struts_config.xml file, the ActionForm should be available to the Action class via the execute() method. When you want to submit the information to a database, it should send whatever values are populated in your ActionForm.
The way I typically call the database is by referencing a button click. If you use the html:submit tag to create your buttons, you can give that button a property. This property can be referenced through the HttpRequest (also passed to the execute() method).
So say I have a button that looks like the following -
<html:submit property="submitButton" value="Submit"/>
I can reference it from the Request by calling a typical getParameter() call using that property as the parameter name.
Example -
(Assume "request" is the reference to the HttpRequest passed to execute())
if (request.getParameter("submitButton") != null) {
// make your database call here by referencing your ActionForm somehow.
Of course, there are plenty of other ways to do it. This is mostly just to give you an example of one way it can be done.
[ February 16, 2004: Message edited by: Rob Aught ]
pie. tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
    Bookmark Topic Watch Topic
  • New Topic