s:if标签判断参数是否为null或者空字符串的方法

代码演示如下

<s:if test="name==null || name==''">  
name是null或者空字符串  
</s:if>  

       说说实际开发中遇到的事,我想通过customerAction_list?select=hehe这个带参数的action访问服务器然后再转发到list.jsp中,因此struts2的ActionContext里面的map集合parameters中就会有select这个值,所以select==hehe;情况2:在我用其它方式请求时(即:不带select这个参数),parameters中就没有这个select值,所以select==null;情况3::如果我设置了selet值的回显,那么这个值就为空字符串,所以select==“”。但是,我直接通过<s:if test="#parameters.select=hehe"或者<s:if test="#parameters.select=‘hehe'"都判断不出来,所以我最终只能判断parameters.select这个值为null还是空字符串,后面我还加了一个jstl与el表达式结合判断的方法,都是针对判断这个事情的,最终却只有后者达到我的目的,这儿只是展示二者的区别。

方法1:采用struts标签判断:(没有成功,不举例了!)


方法2:采用el和jstl判断:(推荐!!!

<c:if test="${param.select=='hehe' }">
    <input type="button" value="选择" onclick="selectCusomer(<s:property value="#cust.cust_id" />,'<s:property value="#cust.cust_name" />')">
</c:if>
<c:if test="${param.select!='hehe' }">
    <a href="${pageContext.request.contextPath }/customerAction_toEdit?cust_id=<s:property value='#cust.cust_id'/>">修改</a>
    <a href="${pageContext.request.contextPath }/customerAction_delete?cust_id=<s:property value='#cust.cust_id'/>">删除</a>
</c:if>


猜你喜欢

转载自blog.csdn.net/Topdandan/article/details/80102302
今日推荐