学习笔记:杂项
一、在web.xml文件配置Struts2过滤器
??????????? <s:property value="#uid"/>
??????????? <s:property value="#attr.uid"/>?
????? 在控件中取值:
??????????? <s:textfield name="name"? value="%{#parameters._KEEP_MULTI_ENTITY}"/>
??????????? <s:textfield name="name"? value="%{#parameters.name}"/>?
四、配置
???? 1、配置包:一个包可以继承其它包。抽象包不能包含Action定义。父包应该在子包前面定义。
?
???? 2、配置命名空间:默认的命名空间是"",命名空间必须以“/”开头。命名空间只有一个级别。
?
???? 3、配置Action:
????????? 当配置Action没有指定class属性时,系统自动使用ActionSupport类作为默认的Action处理类。
????????? 1)、动态方法调用
??????????????? 调用格式:ActionName!methodName.action
??????????????? 需要设置struts.enable.DynamicMethodInvocation为true????????? 2)、为action元素指定method属性
??????????????? <action name="login" method="login">??????????????? </action>
????????? 3)、使用通配符
??????????????? <action name="*Action" method="{1}">
??????????????? <action name="*_*" method="{2}">
??????????????? <action name="*">
????????????????????? <result>/{1}.jsp</result>
??????????????? </action>????????? 4)、默认Action
??????????????? <default-action-ref name="defaultAction">?
???? 4、配置结果:
????????? 1)、Struts2默认的结果类型是dispatcher,结果默认的name属性值为success
??????????????? <result name="success" type="dispatcher">
????????????????????? <param name="location">/login.jsp</param>
????????????????????? <param name="charSet">GBK</param>
??????????????? </result>????????? 2)、redirect-action结果类型:
??????????????? <result name="success" type="dispatcher">
????????????????????? <param name="actionName">show</param>
????????????????????? <param name="namespace">/sales</param>
??????????????? </result>????????? 3)、在结果里使用OGNL表达式
??????????????? 格式:${属性名},属性名就是对应Action实例里的属性。
??????????????? <result>/${currentSkill.name}.jsp</result>????????? 4)、全局结果
??????????????? <global-results>
????????????????????? <result name="success">/target.jsp</result>
??????????????? </global-results>?
???? 5、配置异常:
????????? 1)、全局异常
??????????????? <global-exception-mappings>
????????????????????? <exception-mapping exception="java.sql.SQLException" result="sql"/>
????????????????????? <exception-mapping exception="java.sql.RuntimeException" result="runtime"/>
??????????????? </global-exception-mappings>????????? 2)、输出异常
??????????????? <s:property value="exception"/>?? 输出异常对象本身
??????????????? <s:property value="exception.message"/>???
??????????????? <s:property value="exceptionStack"/>?? 输出异常堆栈信息?
???? 6、结果类型的用法
????????? 1)、stream
?
?
???? 7、Struts2核心对象
????????? 1)、ServletActionContext
???????????????? HttpServletRequest request = ServletActionContext.getRequest();
???????????????? HttpServletResponse response = ServletActionContext.getResponse();
???????????????? ServletContext servletContext = ServletActionContext.getServletContext();
???????????????? ValueStack valueStack = ServletActionContext.getValueStack(request);
???????????????? PageContext pageContext = ServletActionContext.getPageContext();
???????????????? ActionContext actionContext = ServletActionContext.getContext();?
????????? 2)、ActionContext
???????????????? ActionContext.getContext().getActionInvocation();? —— return ActionInvocation
???????????????? ActionContext.getContext().getApplication();? —— return Map
???????????????? ActionContext.getContext().getSession();? —— return Map
???????????????? ActionContext.getContext().getParameters();? —— return Map
???????????????? ActionContext.getContext().getValueStack();? —— return ValueStack
???????????????? ActionContext.getContext().getContainer();? —— return Container
???????????????? ActionContext.getContext().get(key);?
????????? 3)、跟Servlet交互的接口
???????????????? ParameterAware
???????????????? ServletRequestAware
???????????????? ServletResponseAware
???????????????? SessionAware
???????????????? ApplicationAware
???????????????? CookiesAware?