Hello, 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. regards, Ahsan.
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