作用:请求与显示相分离
namespace
namespace 为空,默认为可以接收所有路径下的action
路径问题
尽量使用绝对路径,struts2中的路径是根据action路径而不是jsp 路径来确定
<% String path = request.getContextPath(); String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; %> <base href="<%=basePath%>" /> <!-- 当前页面的所有链接都在这个basepath上 -->
action接收参数
1、接收action传递过来的参数
在action内设置成员变量,以及get 、set 方法
2、使用Domain model 接收参数
域模型相当于实际问题中的实体概念,模型中的属性和参数中的属性不对应的时候不可使用
3、DTO数据传输对象
4、ModelDrivenParamInput 实现了getModel()方法
获取页面元素Map类型 request、session、application
依赖于容器
request = (Map)ActionContext.getContext().get("request"); session = ActionContext.getContext().getSession(); application = ActionContext.getContext().getApplication();
IoC(inverse of control )、DI(dependency injection)
实现这些接口,这些接口中有setRequest(Map<String, Object> request)......方法,实现这些方法。里面的参数通过struts 初始化implements RequestAware,SessionAware, ApplicationAware
模块包含,实用于分模块开发时
<include file="login.xml" />
</pre></div></blockquote></div><div><h3>默认action,当找不到相应的action时调用默认action<span style="white-space:pre"> </span></h3></div><blockquote style="margin: 0 0 0 40px; border: none; padding: 0px;"><div><div><pre code_snippet_id="112508" snippet_file_name="blog_20131214_6_8458544" name="code" class="html"><default-action-ref name="index"></default-action-ref>
接收参数包含中文
<constant name="struts.i18n.encoding" value="GBK" />
具体视图的返回可以由用户自己定义的action来决定:根据返回的字符串找到对应的配置项,来决定视图的内容
DMI 动态方法调用,不用指定调用哪个方法,避免了使用method方法有太多的action
使用通配符指定调用哪个action
<s:property> 取value stack 中的内容
OGNL(object graph navigation language )
方法
读文档;先开发原型,迭代式开发;读书不要抠,了解,大概;