0

I know this is a very common question but i can't find any answer useful for me. I'm working in a spring application using hibernate and getting data from an oracle database. When i insert data into the database one of the fields is the current date that i format like this:

DateFormat dateFormat = new SimpleDateFormat("dd-MMM-yyyy");
Date date = new Date();

And it works fine!

My problem is that when i want to print that date in a JSP it returns like this:

Fecha del mensaje: 2013-06-04 00:00:00

I want to display the date in this way: dd-MMM-YYYY but i just don't know how. As i said before i'm working with spring and hibernate templates.

The code in my controllers is :

@RequestMapping(value="/detalle", method=RequestMethod.GET)
    public String detail(HttpServletRequest req, Map<String, Object> map){

        map.put("details", service.solPorId(req.getParameter("id_sol")));
        map.put("files", service.getFileId(req.getParameter("id_sol")));

        return "gestor/detalles";
    }

The method service.solPorId("anyId") just do a select * from ... where id_sol=anyId

And I'm calling the data in the JSP like this:

<c:forEach items="${details}" var="det">

<h2>Solicitud No. <c:out value="${det.id_sol}" /></h2>

<p>Alumno: <c:out value="${det.nombre}" /> <c:out value="${det.apellido}" /></p>
<p>Especialidad: <c:out value="${det.especialidad}" /></p>
<p>C&oacute;digo: <c:out value="${det.codigo}" /></p>
<p>Ciclo: <c:out value="${det.ciclo}" /></p>
<p>Asunto: <c:out value="${det.asunto}" /></p>
<p>Cuerpo del mensaje:</p>
<p><c:out value="${det.descripcion}" /></p>
<p>Fecha del mensaje:  <c:out value="${det.fecha}" /></p>

So anybody can help me in how to format that date ? Thanks in advance, and sorry for my bad english :(

1 Answer 1

1
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>

....

  <fmt:formatDate value="${det.fecha}" pattern="dd-MMM-YYYY" />
Sign up to request clarification or add additional context in comments.

1 Comment

but that is JSF. I'm using JSTL, they can work together? I don't really know to much about that. Can you give me an example?. Thanks in Advance.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.