Struts2小知识点1

来源:互联网 发布:猎户座飞船知乎 编辑:程序博客网 时间:2024/06/05 15:01

1、jsp引用s标签:

<%@taglib uri="/struts-tags" prefix="s" %>

 

2、struts2中的jsp页面可用<debug></debug>来调试;

      可用<s:property/>来取堆栈中的值。

 

3、堆栈解析

actionErrors:action错误

fieldErrors:action 中 属性错误

errors:包括actionErrors和fieldErrors

error本身是一个Map,errors.name取到的是name的值,该值是一个字符型数组。可通过下标来取。errors.name[0]

 

4、Struts2取得默认action

<package name="default" namespace="/" extends="struts-default">    <default-action-ref name="index"></default-action-ref>    <action name="index">    <result>/default.jsp</result>    </action></package>

指定一个默认的action,当程序访问的action没有匹配到时,系统会自动找到默认的action。因此可以用来处理将出错的页面统一转到一个报错提示的页面。e

 

5、Struts2结果类型 result_type

默认是dispatcher:服务端跳转,地址还是action

redirect:客户端跳转,地址变为jsp

chain:farward访问action(action前不加/)

redirectAction:redirect访问action

<package name="resultTypes" namespace="/r" extends="struts-default">    <action name="r1">    <result type="dispatcher">/r1.jsp</result>    </action>        <action name="r2">    <result type="redirect">/r2.jsp</result>    </action>        <action name="r3">    <result type="chain">r1</result>    </action>        <action name="r4">    <result type="redirectAction">r2</result>    </action>    </package>


6、值栈取值

<s:property value=""/>

 

7、actionContext取值

<s:property value="# "/>
 

 

原创粉丝点击