struts1 总结吧

以前都是使用struts2,但是新公司要使用struts1,所有只有硬着头皮上了。

一、Dynamic Method Invoc

1: 自定义的 Action 必须继承 DispatchAction 而不能继承  Action

public class UserAction extends DispatchAction

 

2:  Action 中不能有 execute(......)  方法 , 否则将始终调用该方法:

 

3: struts-config 配置文件中应该增加如下配置:
<action 。。。。parameter="method" > </action> ====================================== <action path="/user" type="org.springframework.web.struts.DelegatingActionProxy" name="user" parameter="method" scope="request"> <forward name="add_success" path="list.jsp"></forward> <forward name="list" path="list.jsp"></forward> </action> ======================================= 4: 通过 path.do?metho=xxx 的形式调用Action中的方法

二、FORM 书写

public class MyProductForm extends ActionForm{
    
    private int id;
    private String goodsName;
    private String goodsNo;
    private String goodsType;
    
    private int[] ids = new int[0];
    
    /** default constructor */
    public MyProductForm() {
    }
    
    public MyProductForm(int id) {
        this.id = id;
    }


    public ActionErrors validate(ActionMapping mapping,
            HttpServletRequest request) {
        // TODO Auto-generated method stub
        return null;
    }

    /** 
     * Method reset
     * @param mapping
     * @param request
     */
    public void reset(ActionMapping mapping, HttpServletRequest request) {
        // TODO Auto-generated method stub
    }
  //........get set......... }

<form-bean name="myProductForm" type="com.sunmo.test.product.MyProductForm" />

二、返回JSON数据

response.setContentType("application/json;charset=UTF-8");  
response.setCharacterEncoding("UTF-8");
String result = "{'success': true, 'msg': '操作成功'}";
PrintWriter pw = null;
try {
    pw = response.getWriter();
    pw.write(result);
    pw.flush();
} catch (IOException e) {
    e.printStackTrace();
}  

return null; 
原文地址:https://www.cnblogs.com/hzm112567/p/3581695.html