java - c :when not null/empty check

标签 java jsp struts jstl

我有一个形式变量 ftDtClo 定义为这样的形式,

public String getFtDtClo () {
  String dateStr = "";
    if(this.getCse().getDtClo()!=null) {
        dStr = DtUtil.formatDate(this.getCse().getgetDtClo(), DtUtil.FORMAT_MM_DD_YYYY_KK_MM_SS);
    }
   return dateStr;            
}

在 JSP 中,代码如下所示,

<c:choose>
        <c:when test="${not empty cseList.ftDtClo}">
        <c:out value="${cseList.ftDtClo}"/>
        </c:when>
        </c:choose>

但是我得到了 foll 异常,

wrapped exception:
javax.servlet.jsp.JspException: javax.servlet.jsp.JspException: An error occurred while evaluating custom action attribute "test" with value "${not empty cseList.ftDtClo}": An error occurred while getting property "ftDtClo" from an instance of class abc.cseDetailLists (java.lang.NullPointerException)
    at org.apache.taglibs.standard.tag.common.core.ImportSupport.acquireString(ImportSupport.java:306)
    at org.apache.taglibs.standard.tag.common.core.ImportSupport.doEndTag(ImportSupport.java:161)

我假设不为空将处理 null 检查。我错过了什么吗?非常感谢任何 i/p。

最佳答案

   <c:choose>
      <c:if test=${cseList != null}>  
        <c:when test="${not empty cseList.ftDtClo}">
        <c:out value="${cseList.ftDtClo}"/>
        </c:when>
       </c:if>
    </c:choose>

关于java - c :when not null/empty check,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15809624/

相关文章:

java - TreeCell 中的绑定(bind)是否会自动删除

java - Java中的多线程

java - 对象的数组列表只是创建对同一对象java的引用

java - .persist() 在新线程的 Spring Roo 中不起作用

java - 在 JSP 日期格式化程序中处理不可解析的字符串

java - JSP/Servlet 设计问题 - 通过 JNDI 使请求/响应全局可用

html - 是否可以在 mySQL/JSP 中使用 URL 参数?

java - IllegalStateException 问题

java - 在 WEB-INF 目录下移动 JSP 时出现问题

java - ActionServlet是单例类吗?背后的原因是什么?