A simple Dispatchaction application

xiaoxiao2021-03-06  100

1. input.jsp: only provide basic two keys: update and delete, of course, the user may add other keys, and other public ActionForward otherValue added value in Action (ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) { } For example, you joined a to join in Dispatchction

public ActionForward addOrder {form UserManipulcationForm userManipulcationForm = (UserManipulcationForm); / * * other code * / return mapping.findForward ( "delete");} (ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)

INPUT.JSP code: <% @ Taglib Uri = "http://jakarta.apache.org/struts/tags-html" prefix = "HTML"%>
address:

2. Update.jsp: When the user presses the UPDATE button in Input.jsp, final transfer to update.jsp

this is the update page

3. Delete.jsp: When the user presses the delete key in Input.jsp, finally go to delete.jsp

this is the delete page

4. My DispatchAction: the following // Created by MyEclipse Struts // XSL source (default): platform: /plugin/com.genuitec.eclipse.cross.easystruts.eclipse_3.8.0/xslt/JavaClass.xslpackage com.yourcompany.struts .

Import javax.servlet.http.httpservletRequest; import javax.servlet.http.httpservletResponse;

Import org.Apache.struts.action.actionform; import org.apache.struts.action.actionforward; import org.apache.struts.action.actionmapping; import org.apache.struts.Dispatchaction;

Import com.yourcompany.struts.form.usermanipulcationform;

/ ** * MyEclipse Struts * Creation date: 08-23-2004 * * XDoclet definition: * @struts: action path = "/ userManipulcation" name = "userManipulcationForm" input = "/ form / userManipulcation.jsp" parameter = "type "scope =" request "* / public class usermanipulcationaction extends dispatchaction {

/ / -------------------------------------------------------------------------------------------- --------- Instance Variables

/ / -------------------------------------------------------------------------------------------- --------- Methods

/ ** * Method execute * @param mapping * @param form * @param request * @param response * @return ActionForward * / public ActionForward update (ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) {UserManipulcationForm userManipulcationForm = (UserManipulcationForm ) form; / * * some other code corresponds to which key press update * / return mapping.findForward ( "update");} public ActionForward delete (ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) {UserManipulcationForm userManipulcationForm = (UserManipulcationForm ) Form; / * * Other code corresponds to it Press the Delete key * / return mapping.findforward ("delete");}}

It is to be noted that the Value in the button is different, and the Dispatchction is used to automate other methods that want to correspond to Value. .

other:

ActionForm:

// create by myeclipse struts // xsl source (default): platform: /plugin/com.genuitec.eclipse.cross.easystruts.eclipse_3.8.0/xslt/javaclass.xsl

Package com.yourcompany.struts.form;

Import org.apache.struts.Action.actionform;

/ ** * myeclipse struts * creation date: 08-23-2004 * * xdoclet definition: * @struts: form name = "usermanipulcationform" * / public class usermanipulcationform extends actionform {

/ / -------------------------------------------------------------------------------------------- --------- Instance Variables

/ ** Address property * / private string address;

/ ** Name Property * / private string name; / ** Method property * / prince;

/ / -------------------------------------------------------------------------------------------- --------- Methods

. / ** * Returns the address * @return String * / public String getAddress () {return address;} / ** * Set the address * @param address The address to set * / public void setAddress (String address) {. THIS.Address = address;

/ ** * returns the name. * @Return string * / public string getName () {Return Name;}

/ ** * set the name. * @Param name the name to set * / public void setname (string name) {this.name = name;}

Public string getMethod () {return method;} {this.method = method;}}

Struts-config.xml:

It should be noted. . Dispatchaction is a different method that distinguishes different Method values ​​by parameter = "method" defined in Struts-Config.xml. . .

转载请注明原文地址:https://www.9cbs.com/read-124437.html

New Post(0)