zoukankan      html  css  js  c++  java
  • 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; 
  • 相关阅读:
    初入职场的一些感悟
    疲惫于时间管理术-应该如何把握时间
    何为有效沟通
    powdesigner生成模型以后导入erwin大坑 oracle12c
    oracle 12c下载及安装全解析(踩坑注意)-win64-12102版本-2019-10-17
    聚集索引与非聚集索引的用法举例与使用注意
    十分钟,带你了解MobX 与 React
    GET https://pic.qyer.com/avatar/008/23/22/84/200?v=1469960206 403 (Forbidden) 图片防盗链
    writing
    使用github pages搭建博客
  • 原文地址:https://www.cnblogs.com/hzm112567/p/3581695.html
Copyright © 2011-2022 走看看