Note that there are some explanatory texts on larger screens.

plurals
  1. POjava.util.Date from <input type="datetime-local" />
    primarykey
    data
    text
    <p>I'm using JSTL with Spring and I've got the code:</p> <pre><code>&lt;form:input type="datetime-local" path="startDate" /&gt; </code></pre> <p>where startDate is a java.util.Date</p> <p>How can I get the date and time from the input? Is there a right way or should I get the string from the input and write code to convert it to java.util.Date?</p> <p>Thanks in advance.</p> <p>This is my nuevaTarea.jsp:</p> <pre><code>&lt;%@ include file="/WEB-INF/jsp/include.jsp" %&gt; &lt;%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %&gt; &lt;%@page contentType="text/html" pageEncoding="UTF-8"%&gt; &lt;!DOCTYPE html&gt; &lt;html&gt; &lt;head&gt; &lt;meta http-equiv="Content-Type" content="text/html; charset=UTF-8"&gt; &lt;title&gt;Nueva tarea&lt;/title&gt; &lt;link rel="stylesheet" type="text/css" href="resources/css/style.css" media="screen" /&gt; &lt;/head&gt; &lt;body&gt; &lt;h1&gt;Nueva tarea&lt;/h1&gt; &lt;form:form action="nuevatarea.htm" method="POST" commandName="tareaForm"&gt; &lt;label&gt;Fecha de inicio:&lt;/label&gt;&lt;form:input type="datetime-local" path="fechaInicio" /&gt;&lt;br /&gt; &lt;label&gt;Fecha de fin:&lt;/label&gt;&lt;form:input type="datetime-local" path="fechaFin" /&gt;&lt;br /&gt; &lt;input type="submit" value="Crear tarea" /&gt; &lt;/form:form&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>This is my TareaForm.java which is the command class:</p> <p>package web.controller;</p> <p>import java.util.Date;</p> <p>public class TareaForm {</p> <pre><code>private Date fechaInicio; private Date fechaFin; public Date getFechaFin() { return fechaFin; } public Date getFechaInicio() { return fechaInicio; } public void setFechaFin(Date fechaFin) { this.fechaFin = fechaFin; } public void setFechaInicio(Date fechaInicio) { this.fechaInicio = fechaInicio; } </code></pre> <p>}</p> <p>And, this is my controller nuevaTareaController.java:</p> <p>package web.controller;</p> <pre><code>import javax.servlet.http.HttpServletRequest; import org.springframework.validation.BindException; import org.springframework.web.servlet.ModelAndView; import org.springframework.web.servlet.mvc.SimpleFormController; public class nuevaTareaController extends SimpleFormController { public nuevaTareaController() { setCommandClass(TareaForm.class); setCommandName("tareaForm"); } @Override protected Object formBackingObject(HttpServletRequest request) throws Exception { return (TareaForm)super.formBackingObject(request); } @Override protected ModelAndView onSubmit(Object command, BindException bindException) throws Exception { // Do something with (TareaForm)command return new ModelAndView(getSuccessView()); } } </code></pre> <p>This is the config of the controller in my dispatcher-servlet:</p> <pre><code>&lt;bean class="web.controller.nuevaTareaController"&gt; &lt;property name="formView" value="nuevaTarea" /&gt; &lt;property name="successView" value="tareaCreada" /&gt; &lt;property name="gestorTareas" ref="tareas" /&gt; &lt;/bean&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload