摘要: . 一个result元素,对应一个result类,类中接收不同的参数; 1)在result路径问题 在result映射的配置中,在指定实际资源的位置时,可以使用绝对路径也可以使用相对路径。 绝对路径是以斜杠(/)开头,相对于当前web项目的上下文路径,相对路径不以斜杠(/)开头, 相当于当前执行的action路径。 <package name="default" extends="struts-default" namespace="/admin"> <action name="login" cl 阅读全文
posted @ 2013-02-13 19:50 一灵 阅读(310) 评论(0) 推荐(0) 编辑
摘要: 动态方法调用两种方式: 1)用"!"无须配置 无须配置就可以直接调用Action中的非execute()方法的方式, 就是使用Struts2的动态方法(DMI)。动态方法调用(DMI)是在action的名字中使用感叹号"!"来标识, 如: http://localhost:8080/day01/show!save 执行Action类中的save方法 http://localhost:8080/day01/show!del 执行Action类中的del方法 2)用通配符需要配置 <package name="ac" extends 阅读全文
posted @ 2013-02-13 18:37 一灵 阅读(193) 评论(0) 推荐(0) 编辑
摘要: 运行时由Struts2注入原生ServletAPI对象: . 由Struts2注入原生HttpServletRequest对像,必须实现ServletRequestAware接口并实现接口中的方法 public void setServletRequest(HttpServletRequest request); . ServletRequestAware接口中只有一个方法: public void setServletRequest(HttpServletRequest request); //该方法是在struts2运行时调用,用于向实现它的类中注入request对象 ... 阅读全文
posted @ 2013-02-13 18:29 一灵 阅读(175) 评论(0) 推荐(0) 编辑
摘要: ActionContext(用new ThreadLocal()邦定了线程) | |--ServletActionContext public class ContextAction extends ActionSupport { public String test(){ //获取request对象 HttpServletRequest request=ServletActionContext.getRequest(); ... 阅读全文
posted @ 2013-02-13 18:17 一灵 阅读(161) 评论(0) 推荐(0) 编辑
摘要: 为了避免与Servlet API耦合在一起,方便Action类做单元测试,Struts2对HttpServletRequest、HttpSession和ServletContext进行了封装,构造了三个Map对象来替代这三种对象,在Action中,直接使用HttpServletRequest、HttpSession、ServletContext对应的Map对象来保存和读取数据。要获得这三个Map对象,可以使用com.opensymphony.xwork2.ActionContext类*.ActionContext - 请求上下文 。- 就是struts2封装的request.包含了reques 阅读全文
posted @ 2013-02-13 17:54 一灵 阅读(472) 评论(0) 推荐(0) 编辑
摘要: .模型驱动实际上就是将JavaBean对象放到栈顶.模型驱动是将多个从页面获取的值直接做用到某个指定的JavaBean上。.模型驱动是通过模型驱动拦截器ModelDriver实现的 .模型驱动的实现必须借助于ModelDriver<T>类。.模型驱动 在页面声明参数和获取数据时不用写user.name,直接写name${requestScope.name},${requestScope.pwd},${requestScope.age} //模型驱动 public class UserModelAction implements ModelDriven<User> ... 阅读全文
posted @ 2013-02-13 17:40 一灵 阅读(264) 评论(0) 推荐(0) 编辑
摘要: . 所谓属性驱动就是把要接收的参数声明为Action类的成员变量(要和参数一一对应),并添加get,set方法就可接收到参数;. Action类本身也可以是javaBean . struts2通过内省机制操作javaBean,并实现封装转发,所以可在结果页上直接从request中获取 1)在Action类中声明的成员变量是基本类型 (但这样Action就成为了javaBean,将javabean和控制代码写在了一起,不复合MVC的规范) public class UserAction { private String nm; ... 阅读全文
posted @ 2013-02-13 17:34 一灵 阅读(231) 评论(0) 推荐(0) 编辑
摘要: 常量可以在struts.xml或struts.properties中配置,建议在struts.xml中配置,两种配置方式如下: 1)在struts.xml文件中配置常量: <struts> <constant name="struts.action.extension" value="do"/> </struts> 2)在struts.properties中配置常量: (struts.properties文件放置在src下) struts.action.extension=do.go 常用常量:<constant 阅读全文
posted @ 2013-02-13 17:13 一灵 阅读(138) 评论(0) 推荐(0) 编辑
摘要: 1)struts.xml文件要放在src目录下,会被編译到\WEB-INF\classes\目录下 2)struts.xml文件可以包含多个 自定义struts.xml文件 ,如struts-user.xml,这些自定义的文件最后必须包含到struts.xml中才会有效; .这样做的好处是可以使庞大的struts.xml,分成各个小的struts.xml文件 .方便项目合并 //包含到struts.xml文件中 <struts> <include file="cn/xt/web/struts-user.xml"/> <include file. 阅读全文
posted @ 2013-02-13 16:58 一灵 阅读(205) 评论(0) 推荐(0) 编辑
摘要: 配置文件加载顺序: web.xml |default.properties 资源文件 |struts-defalut.xml配置文件 |struts-plugin.xml插件文件 | struts.xml用户配置 <struts> <package name="xt11" namespace="/xt" extends="struts-default"> <action name="test" class="cn.xt.work.Test"> <para 阅读全文
posted @ 2013-02-13 16:46 一灵 阅读(221) 评论(0) 推荐(0) 编辑