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

本文详细介绍了Struts2框架中的标签使用方法,包括如何访问静态变量和方法、解决直接访问jsp出现的问题、if标签的字符串包含判断及处理NoResultDefined异常的方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 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>

 

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

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

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值