-1

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;
  </sql:query>
</sql:transaction>

<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],'-',',')}" />
</c:forEach>

<%
    Calendar d = Calendar.getInstance();
    d.set(date);
%>

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

Edited by doniandric: add additional tag

2
Contributors
3
Replies
5
Views
4 Years
Discussion Span
Last Post by subramanya.vl
0

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();
d.set((String)pageContext.getAttribute("date"));
%>

Hope this will help

Edited by subramanya.vl

0

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); 
               c.set(int0,int1,int2); 
             } 
          %>
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.