如何检查我的值是否为null或为空? [英] How to check if my value is null or empty?

查看:103
本文介绍了如何检查我的值是否为null或为空?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的JSP代码中,我有以下内容:

In my JSP code I have the following:

<s:iterator value="details" id="cle" status="rowCle">
    <s:iterator value="value" status="row" >
     <tr>
       <s:if test="%{#surname== ''}">
        <td>&nbsp;</td>
       </s:if>
       <s:else>
            <td class="reference"><s:property value="%{getText(key.longname.toLowerCase()) }" /></td>
       </s:else>

根据姓氏的值(这是我的对象详细信息中带有getter的字段,因此它位于值堆栈中),我要显示值longname或空白.

Depending on the value of surname (which is a field with getter in my object details, so it is in the value stack) I want to display the value longname or blank.

我没有显示{getText(key.longname.toLowerCase())的问题,我稍后还会在代码中显示姓氏,因此我唯一关心的是测试姓氏的内容以检查其是否为空或为空.

I have no problem to display {getText(key.longname.toLowerCase()), I also display surname later in my code, so my only concern is about testing the content of surname to check if it is null or empty.

我尝试了多种选择,例如

I have tried several options such as

"%{#surname== ''}">
%{surname== null}'>
'%{#surname== null}'>

,但没有一个有效.

我有点迷茫.有人可以解决吗?

I am a bit lost. anybody would have a solution please?

谢谢. B.

推荐答案

使用验证效果更好.因此,这些验证代码将从视图层(JSP)中删除.您可以通过扩展ActionSupport将方法validate()继承到您的操作类. 在此处添加您的验证码.如果验证发现任何错误,它将显示在jsp页面文本框上方.

Its better using validation.So that these validation codes will be removed from view layer(JSP). You can inherit method validate() to your action class by extending ActionSupport. Add your validation codes here.If validation catch any error it will show above the jsp page textbox.

这篇关于如何检查我的值是否为null或为空?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆