在 JSP 上使用 JSTL 变量

  • 本文关键字:JSTL 变量 JSP jsp jstl
  • 更新时间 :
  • 英文 :


如何使用JSTL变量,如下所示:

         <c:set var="datetime" value="${fn:split(starttime,' ')}" />
         <c:set var="date" value="${fn:replace(datetime[0],':',',')}" />

稍后用于以下内容:

         <c:if test="${param.cid!=null}">
         <%
              Calendar d = Calendar.getInstance();
              d.set(out.print(<c:out value="${date}"/>);
         %>
         </c:if>

已编辑

我终于做了一些实验,发现了这样的东西:

         <% Calendar c = Calendar.getInstance();
            if(pageContext.getAttribute("date") != null)
            { 
               String datez = (String)pageContext.getAttribute("date"); 
               String dates[] = datez.split(","); 
               String date0 = dates[0]; 
               String date1 = dates[1]; 
               String date2 = dates[2]; 
               int int0 = Integer.parseInt(date0); 
               int int1 = Integer.parseInt(date1) - 1; 
               int int2 = Integer.parseInt(date2); 
               c.set(int0,int1,int2); 
             } 
          %>  

有什么更好的主意吗?

不能在 scriptlet 中使用表达式语言,因为它们应该只包含 Java 代码。顺便说一下,通常脚本是糟糕的做法,JSTL 和 EL 旨在替换它们。

最新更新