日期:2014-05-19  浏览次数:21191 次

判断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>