Layers of Progressive Struts1 (vii) detailed dispatchaction

Source: Internet
Author: User
Tags modify

Through the previous several blogs, do not know whether we have found this problem, although now can be flexible control jump, but the number of action is still more, how to ensure that the jump flexibility, but also reduce the number of action? This is what our blog says about Dispatchaction, which, like its name, can be understood as a "distribution action," which avoids creating a class for each action.

Let's take a look at the examples first.

Useraction

Dispatchaction inherits the action, which is characterized by merging the previous action into one, which, when multiple action associations are large, can be put together like this, reducing the action class and reducing the difficulty of maintenance.

Package com.tgb.drp.web.actions;  
Import Java.util.Date;  
      
Import java.util.List;  
Import Javax.servlet.http.HttpServletRequest;  
      
Import Javax.servlet.http.HttpServletResponse;  
Import Org.apache.commons.beanutils.BeanUtils;  
Import Org.apache.struts.action.ActionForm;  
Import Org.apache.struts.action.ActionForward;  
Import org.apache.struts.action.ActionMapping;  
      
Import org.apache.struts.actions.DispatchAction;  
Import Com.tgb.drp.manager.UserManager;  
Import Com.tgb.drp.model.User;  
      
Import Com.tgb.drp.web.forms.UserActionForm; public class Useraction extends Dispatchaction {@Override protected actionforward unspecified (Actionmapp  ing mapping, actionform form, httpservletrequest request, httpservletresponse response) throws  
        Exception {//Call business logic operations List userlist = Usermanager.getinstance (). Findalluserlist ();  
           Request.setattribute ("UserList", userlist);   
        Return Mapping.findforward ("list_success"); 
     /** * User deleted * @param mapping * @param form * @param request * @param response  
            * @return * @throws Exception/public Actionforward del (actionmapping Mapping, Actionform form, HttpServletRequest request, HttpServletResponse response) throws Exception {//Get from page form  
              
        The value submitted over the Useractionform UAF = (useractionform) Form;  
      
        Obtain the set of UserID that need to be removed string[] useridlist = Uaf.getselectflag ();  
        Invoke Business logic Operations Usermanager.getinstance (). Deleteusers (Useridlist);  
    Return Mapping.findforward ("del_success"); /** * User Add * @param mapping * @param form * @param request * @param RESPO NSE * @return * @throws Exception/Public actionforward Add (actionmapping mapping, actionform form , HttpseRvletrequest request, HttpServletResponse response) throws Exception {//Get submitted from page form  
        Come over the value useractionform UAF = (useractionform) Form;  
        User user = new user ();  
        Beanutils.copyproperties (user, UAF);  
              
        User.setcreatedate (New Date ());  
        Invoke Business logic Operations Usermanager.getinstance (). AddUser (user);  Return Mapping.findforward ("add_success"); 
     /** * Modify User * @param mapping * @param form * @param request * @param response   
            * @return * @throws Exception/Public Actionforward Modify (actionmapping mapping, Actionform form, HttpServletRequest request, HttpServletResponse response) throws Exception {//Get from page  
        The value submitted in the surface form useractionform UAF = (useractionform) Form;  
        User user = new user ();  
              
        Beanutils.copyproperties (user, UAF);  
       Calling business logic operations Usermanager.getinstance (). ModifyUser (user);  
    Return Mapping.findforward ("modify_success");  /** * Query users by ID * * @param mapping * @param form * @param request * @param response * @return * @throws Exception/public Actionforward find (actionmapping mapping, A  
        Ctionform form, httpservletrequest request, httpservletresponse response) throws Exception {  
              
        Gets the value submitted from the page form useractionform UAF = (useractionform) Form;  
              
        String userId = Uaf.getuserid ();  
              
        Invoke Business logic Action User user = Usermanager.getinstance (). Finduserbyid (UserId);  
              
        Pass the user object from the action to the JSP page Request.setattribute ("user", user);  
    Return Mapping.findforward ("find_success"); }  
          
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.