struts1 总结吧
2024-09-06 11:46:25
以前都是使用struts2,但是新公司要使用struts1,所有只有硬着头皮上了。
一、Dynamic Method Invoc
: 自定义的 Action 必须继承 DispatchAction 而不能继承 Action public class UserAction extends DispatchAction : Action 中不能有 execute(......) 方法 , 否则将始终调用该方法: : 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>
======================================= : 通过 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;
最新文章
- ASP.NET跨平台最佳实践
- UVa 712 S树
- CentOS 7 运行级别切换
- 注意,ruby循环体定义的变量在结束时后,变量还存在
- 传说中的WCF(9):流与文件传输
- C++ 四则运算简单设计
- bzoj3261: 最大异或和
- DLL程序的创建步骤和測试程序
- QML之窗口(无边框、透明及拖拽)
- 设计模式--装饰者设计模式(Decorator)
- 英文汉语切换的导航栏,纯css制作。
- Linux必备操作vim
- Github上怎么修改别人的项目并且提交给原作者!图文并茂!
- 知识小罐头03(idea+maven+部署war包到tomcat 上)
- cssselector元素定位
- 买了第一台mac
- IIS 域名 带参数 设置重定向
- RecyclerView错误
- img的src不连接本地地址实现输出一个图片(使用base64)
- 二,windows下安装memcached服务