0

I have the following sourcecode:

<c:set var="runtimeEnd" value="${content.valueList.Promotion[0].value.RuntimeEnd}"/>

which is a number in jsp and stands for a date for example: 1425769140000

how do i access this variable in Java? imean when i do the following it wont even load the page anymore:

<% out.println(${runtimeEnd}); %>

I would like to insert the variable into the following JAVA code to display the date

<% SimpleDateFormat simpleDateFormat = new SimpleDateFormat("dd MMMMMMMMM yyyy");
out.println(simpleDateFormat.format(${runtimeEnd})); %>
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
Snackaholic
  • 590
  • 7
  • 27

1 Answers1

1

Why do you want to use scriplets? Do the work with jstl library if you have started with it.

JSTL Format Date library seems is what you need.

Example:

<c:set var="runtimeEnd" value="${content.valueList.Promotion[0].value.RuntimeEnd}"/>
<fmt:formatDate pattern="yyyy-MM-dd" value="${runtimeEnd}" />

P.S. To print a variable using jstl library, use <c:out value="This will be printed" /> tag.

Scriplets approach:

Printing:

 <%=pageContext.getAttribute("runtimeEnd") %>

Formatting:

<% SimpleDateFormat simpleDateFormat = new SimpleDateFormat("dd-MM-yyyy"); 
String convertedDate = String.valueOf(pageContext.getAttribute("runtimeEnd"));
%>
<%=simpleDateFormat.format(convertedDate); %>
drgPP
  • 926
  • 2
  • 7
  • 22
  • @TeaTime you can store it in a variable inside fmt tag using var key, like , and if you want to print it, pass it to out tag value. – drgPP Aug 03 '15 at 07:45
  • wont work : – Snackaholic Aug 03 '15 at 07:47
  • @TeaTime be sure what the value of runtimeEnd is a String, and you add the taglib declaration in the top of your jsp <%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %> – drgPP Aug 03 '15 at 07:51
  • @TeaTime check my Edit. – drgPP Aug 03 '15 at 08:10
  • Thanks for your help :) the thing was i forgot to add the fmt library. Also the simpleDateFormat way is unneccessarry since the expression language works great – Snackaholic Aug 03 '15 at 08:40