标签:class code ext get int strong
|
1
2
3
4
5 |
Web.xml 设置过滤器以及annotation初始化参数 Struts.xml 主配置文件 Struts.properties 默认属性文件 Struts-default.xml 默认配置文件 Struts-plugin.xml 插件配置文件 |
|
1
2
3
4
5
6
7
8 |
由上至下,以此为:Struts-default.xmlStruts-plugin.xmlStruts.xmlStruts.propertiesWeb.xml如果在多个文件中配置了同一个Struts2常量,则后一个文件中的配置的常量值将覆盖前面文件中配置的常量值。在不同文件中配置常量的方式是不一样的,但不管哪个文件中,配置Struts2常量都要指定两个属性:常量name和常量value推荐在struts.xml文件中配置Struts2常量 |
|
1
2
3
4
5
6
7 |
Bean元素属性 class:必选,指定了Bean实例的实现类 type:可选,通常是通过某个接口或者在此前定一个过的Bean name:可选,它指定的Bean实例的名字,对于有相同type的多个Bean,name必须唯一 scope:可选,指定Bean的作用域,只能是default、singleton、request、session和thread之一 static:可选,它指定Bean是否使用静态方法注入。通常而言,当指定了type属性时,该属性就不应该设置为trueoptional:可选,指定Bean是否是一个可选Bean |
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38 |
##字符集 struts.i18n.encoding=UTF-8 struts.objectFactory.spring.autoWire = name struts.objectFactory.spring.useClassCache = truestruts.objectFactory.spring.autoWire.alwaysRespect = falsestruts.multipart.parser=jakartastruts.multipart.saveDir=struts.multipart.maxSize=2097152 ##请求后缀 struts.action.extension=action,, struts.serve.static=truestruts.serve.static.browserCache=truestruts.enable.DynamicMethodInvocation = falsestruts.enable.SlashesInActionNames = falsestruts.mapper.action.prefix.enabled = falsestruts.mapper.action.prefix.crossNamespaces = falsestruts.tag.altSyntax=true##开发模式 struts.devMode = falsestruts.i18n.reload=falsestruts.ui.theme=xhtmlstruts.ui.templateDir=template struts.ui.theme.expansion.token=~~~struts.ui.templateSuffix=ftl struts.configuration.xml.reload=falsestruts.velocity.configfile = velocity.properties struts.velocity.contexts = struts.velocity.toolboxlocation= struts.url.http.port = 80struts.url.https.port = 443 struts.url.includeParams = none struts.dispatcher.parametersWorkaround = falsestruts.freemarker.templatesCache=falsestruts.freemarker.beanwrapperCache=falsestruts.freemarker.wrapper.altMap=truestruts.freemarker.mru.max.strong.size=0 struts.xslt.nocache=falsestruts.mapper.alwaysSelectFullNamespace=falsestruts.ognl.allowStaticMethodAccess=falsestruts.el.throwExceptionOnFailure=falsestruts.ognl.logMissingProperties=falsestruts.ognl.enableExpressionCache=truestruts.handle.exception=true |
|
1
2
3
4
5
6
7
8
9
10
11
12 |
<struts> <!--重置属性—> <constant name="struts.devMode"
value="true"> </constant> <constant name="struts.i18n.encoding"
value="urf-8"></constant> <!--定义包—> <package name="default"
namespace="/"
extend="struts-default"> <!--动作—> <action name=""
class=""> <result name=""
class=""
></result> </action> </package> </struts> |
|
1
2
3
4
5
6
7
8
9
10 |
Constant 常量 Package 包 解决Action重名,方便继承 -name 包名 -extends 父包名 -namespace
命名空间 Action -name 动作名 -class
实现类 global-results 全局结果 Result 局部结果 |
|
1
2
3 |
<action name="admin"
class="net.nw.action.AdminAction"
method="add"> <result>result.jsp</result></action> |
|
1
2
3
4 |
<action name="admin"
class="net.nw.action.AdminAction"> <result>result.jsp</result></action><a href="<%=path%>/admin/admin!add.action">添加</a> |
|
1
2
3
4 |
<default-action-ref
name="error"></default-action-ref><action name="error"> <result>error.jsp</result></action> |
|
1
2
3 |
<action name="Student*"
class="net.nw.struts2.action.StudentAction"
method="{1}"> <result>/Student{1}_success.jsp</result></action> |
|
1
2
3
4
5 |
{0} 表示匹配所有内容{1} 表示前面的第一个*的内容* 0-N不包括 "/"** 0-N包括 "/"\ 转义符 |
|
1 |
引入struts2-convention-plugin-2.2.1.jar包 |
|
1
2
3
4
5
6
7
8
9
10
11
12 |
//web.xml<filter> …… <init-param> <param-name>actionPackages</param-name> <param-value>net.nw.action</param-value> </init-param> <init-param> <param-name>encoding</param-name> <param-value>UTF-8</param-value> </init-param></filter> |
|
1
2
3
4
5
6
7
8 |
//注解@parentPackage(value="struts-default")@Namespace(value="/")@Result(name="login_success",location="/login_success.jsp")@Results({@Result(name="login_success",location="/login_success.jsp","type="redirect"),@Result(name="login_failure",location="/login_failure.jsp","type="redirect")}) |
|
1 |
<include file="admin.xml"> |
|
1
2
3 |
<action name="**"> <result>error.jsp</result></action> |
|
1
2
3 |
Map request = (Map)ActionContext.getContext().get("request");Map session = ActionContext.getContext().getsession();Map application = ActionContext.getContext().getApplication(); |
|
1
2
3 |
HttpServletReques request = ServletActionContext.getRequest();HttpSession session = request.getSession();ServletContext application = session.getServletContext(); |
|
1
2
3
4
5
6
7
8
9
10 |
Dispatcher:转发到URL,通常是JSP(服务器)Redirect:重定向到URL,通常是JSP(客户端)Chain:转发到一个Action(服务器)redirectAction:重定向到一个Action(客户端)freemarker:处理FreeMarker模型Httpheader:控制特殊HTTP行为的结果类型Stream:向浏览器发送InputSream对象,通常用来处理文件下载,还可用于返回AJAX数据Velocity:处理Velocity模版Xslt:处理XML/XLST模版plainText:显示原始文件内容,例如文件源代码 |
Struts2.X深入浅出 学习笔记,布布扣,bubuko.com
标签:class code ext get int strong
原文地址:http://www.cnblogs.com/linzhenjie/p/3704674.html