`

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.No result defined for action and result input

 

一种原因是struts2的action及返回值的配置有问题,仔细检查。

 

如果发现配置没有问题,很大可能是页面提交的from的数据有问题,比如:

 

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

 

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

 

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

 

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

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

 

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics