读书人

Struts2标签常见有关问题(持续更新)

发布时间: 2012-10-14 14:55:08 作者: rapoo

Struts2标签常见问题(持续更新)

?1.Struts2标签中访问静态变量或者方法

?

例如:

?

<s:proptery value="@cn.com.victorysoft.datasource.standard.action.StorageClass@STATIC_NAME"/>

?

<s:if test="#session.deptid==@cn.com.victorysoft.datasource.standard.action.StorageClass@STATIC_NAME"></s:if>
?
<s:iterator id="show11" value="@cn.com.victorysoft.datasource.standard.action.StorageClass@STATIC_NAME"></s:iterator>

?

注意:

??? 1.访问的类名必须是全称。是@cn.com.victorysoft.datasource.standard.action.StorageClass而不是@StorageClass

??? 2.在版本2.1.2中,如果要通过ognl访问静态方法,必须在struts.properties或者struts.xml中将选项struts.ognl.allowStaticMethodAccess设置为true

?

2.直接访问jsp出现异常:

?

The Struts dispatcher cannot be found.? This is usually caused by using Struts tags without the associated filter. Struts tags are only usable when the request has passed through its servlet filter, which initializes the Struts dispatcher needed for this tag. - [unknown location]

?

解决方法:在web.xml中加一个过滤设置

?

<filter-mapping>      <filter-name>struts2</filter-name>      <url-pattern>*.jsp</url-pattern> </filter-mapping>  

?

3.if标签判断一个字符串是否包含一个字符串

?

<s:if test="#str.indexOf('abc')>=0">    yes</s:if><s:else>    no</s:else>
?

4.<input type="text" name="userId" value="<%=userId%>"/>

?

仔细检查jsp页面中from的数据,当然,在struts2的xml配置文件中加上:

?

<result name="input">/error.jsp</result>

?

把错误返回到页面,就一目了然了。

很明显,这是输入异常的一种。

?

?

读书人网 >软件架构设计

热点推荐