i have certain codes in JSP and JSTL as following :

<sql:transaction dataSource="${dataBase}">
  <sql:query var="tDate">
       SELECT starttime FROM campaign WHERE cid=25;

<c:forEach var="row" items="${tDate.rows}" varStatus="totalRow" step="1">
<c:set var="starttime" value="${row.starttime}" />
<c:set var="datetime" value="${fn:split(starttime,' ')}" />
<c:set var="date" value="${fn:replace(datetime[0],'-',',')}" />

    Calendar d = Calendar.getInstance();

but apparently, it didn't work. So, how to solve this?

Edited by doniandric: add additional tag

5 Years
Discussion Span
Last Post by subramanya.vl

First thing i observe that you are iterating a collection(row) and getting value date from the collection.
Hence there will not be just one "date", but there will be same nubmer "date" which is equal to the size of the collection "row".

Hence the logic is not correct here, since you are trying to get only one "date" where as there could be many such "date".

Assuming that there is only one "date" in the jstl code ( means you are not iterating any collection).
Using below code can get the value from JSTL to scriptlet.

Calendar d = Calendar.getInstance();

Hope this will help

Edited by subramanya.vl


thanks a lot. It brought me a new idea. I just changed a bit my codes like this:

 <% 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); 
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.