当前位置: 代码迷 >> J2EE >> 判断s:if test里头的值包含字符串
  详细解决方案

判断s:if test里头的值包含字符串

热度:56   发布时间:2016-04-22 01:01:47.0
判断s:if test里面的值包含字符串
HTML code
 <s:if test="<s:property value='item.name' />.contains('全能')">                                              1                                              </s:if>



写成这样不行,就是实现这样的功能

用s:if去判断 <s:property value='item.name' /> 这个的值里面是否包含‘全能’两字,


用JSP 写

HTML code
     <%                                            String teamName1 = <s:property value="item.name" />                                                                                              if (teamName1.contains("全能")) {                                        %>                                        <input type="hidden" id="sex" name="athlete.sex" value="男" />                                        <%                                            }                                          %>


这样 页面直接报错了。

------解决方案--------------------
直接借助indexOf函数吧,你试试看:
<s:if test="%{item.name.indexOf('全能')>=0}"> 


------解决方案--------------------
HTML code
<c:choose>                                                                <c:when test="${fn:contains(item.name,'全能')}">                          1                                                                </c:when>                                                                <c:otherwise>                                                           2                                                                  </c:otherwise>                                                            </c:choose>
  相关解决方案