您的位置:首页 > 移动开发

struts1_MappingDispatchAction

2015-08-12 00:00 316 查看
摘要: MappingDispatchAction 这样就避免了写多个Action

下面是请求的html:

<html:link action="/addbook">添加图书</html:link>
<html:link action="/deletebook">删除图书</html:link>
<html:link action="/updatebook">修改图书</html:link>
<html:link action="/findbook">查找图书</html:link>


下面是struts-config.xml文件:

<?xml version="1.0" encoding="UTF-8" ?>

<!DOCTYPE struts-config PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 1.3//EN"
"http://struts.apache.org/dtds/struts-config_1_3.dtd">

<struts-config>

<action-mappings>
<action path="/addbook" type="cn.itcast.web.action.BookAction2" parameter="add"/>
<action path="/updatebook" type="cn.itcast.web.action.BookAction2" parameter="update"/>
<action path="/findbook" type="cn.itcast.web.action.BookAction2" parameter="find"/>
<action path="/deletebook" type="cn.itcast.web.action.BookAction2" parameter="delete"/>
</action-mappings>

</struts-config>


下面是请求的java文件:

public class BookAction2 extends MappingDispatchAction {

public ActionForward add(ActionMapping arg0, ActionForm arg1,
HttpServletRequest arg2, HttpServletResponse arg3) throws Exception {

System.out.println("add....");
return null;
}

public ActionForward update(ActionMapping arg0, ActionForm arg1,
HttpServletRequest arg2, HttpServletResponse arg3) throws Exception {
// TODO Auto-generated method stub

System.out.println("udpate....");
return null;
}

public ActionForward delete(ActionMapping arg0, ActionForm arg1,
HttpServletRequest arg2, HttpServletResponse arg3) throws Exception {
// TODO Auto-generated method stub

System.out.println("delete....");
return null;
}

public ActionForward find(ActionMapping arg0, ActionForm arg1,
HttpServletRequest arg2, HttpServletResponse arg3) throws Exception {
// TODO Auto-generated method stub
System.out.println("find....");
return null;
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  MappingDispatchAction