struts1_DispatchAction 可以同时处理多个请求的Action
2015-08-12 00:00
218 查看
摘要: struts1_DispatchAction 可以同时处理多个请求的Action
下面是一段:html请求
下面是配置文件:struts-config.xml
下面是处理请求的java代码:
下面是一段:html请求
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> <%@taglib uri="http://struts.apache.org/tags-html" prefix="html" %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>My JSP '1.jsp' starting page</title> </head> <body> <html:link action="/BookAction?method=add">添加图书</html:link> <html:link action="/BookAction?method=delete">删除图书</html:link> <html:link action="/BookAction?method=update">修改图书</html:link> <html:link action="/BookAction?method=find">查找图书</html:link> <br/> <br/>---------------------------------------------<br/><br/> <html:link action="/addbook">添加图书</html:link> <html:link action="/deletebook">删除图书</html:link> <html:link action="/updatebook">修改图书</html:link> <html:link action="/findbook">查找图书</html:link> </body> </html>
下面是配置文件: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="/BookAction" type="cn.itcast.web.action.BookAction" parameter="method"> <!-- 告诉struts,要调用的方法名称是通过什么参数带过来的 --> </action> </action-mappings> </struts-config>
下面是处理请求的java代码:
//DispatchAction---action ---execute() add /* String method = mapping.getParamter();//拿到配置的参数的名称:method String methodName = request.getParameter(method); //add update拿到的是请求参数method对应的值:add还是delete。。。 然后反射BookAction,调用对应的请求方法 * */ public class BookAction extends DispatchAction { 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; } }
相关文章推荐
- struts1——指定多个配置文件(struts-config.xml)
- struts1——动态formbean
- struts1——Validator框架的校验过程
- eclipseRCP深入浅出(学习总结)2015.08.11
- Java垃圾回收机制 入门
- Java集合框架 入门
- Java异常处理机制
- MyEclipse设置Java代码注释模板
- JAVA 汉字ASCII范围
- springmvc 上传文件 type=file name=imagepath request转换出
- 解决一个少见的错误java.lang.NoClassDefFoundError
- eclipseRCP深入浅出(学习总结)2015.08.08
- 从源码来理解ArrayList和LinkedList区别
- Java并发教程
- java基础--多线程
- spring 之jdbcTemplate使用
- Java synchronized详解
- java一些常见常识
- java 重写的学习
- java 继承的学习(转)