Get Date value from Form : Form Input « JSTL « Java Tutorial






index.jsp

<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %>

<form method="post" action="dateHandler.jsp">

  Please enter your birthday:

  <select name="month">
    <option value="Jan">January</option>
    <option value="Feb">February</option>
    <option value="Mar">March</option>
    <option value="Apr">April</option>
    <option value="May">May</option>
    <option value="Jun">June</option>
    <option value="Jul">July</option>
    <option value="Aug">August</option>
    <option value="Sep">September</option>
    <option value="Oct">October</option>
    <option value="Nov">November</option>
    <option value="Dec">December</option>
  </select>

  <select name="day">
    <c:forEach begin="1" end="31" var="day">
      <option><c:out value="${day}"/></option>
    </c:forEach>
  </select>

  <select name="year">
    <c:forEach begin="1930" end="2003" var="year">
      <option><c:out value="${year}"/></option>
    </c:forEach>
  </select>

  <input type="submit" value="Submit" />

</form>

dateHandler.jsp

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

<fmt:parseDate
  var="date"
  parseLocale="en_US"
  value="${param.month} ${param.day}, ${param.year}"/>

You were born
<fmt:formatDate
  value="${date}"
  dateStyle="full"/>.
  Download:  JSTLPassDateFromForm.zip( 939 k)








24.15.Form Input
24.15.1.Use ForEach to List All Form Parameters
24.15.2.Set Parameter Value
24.15.3.Get Date value from Form
24.15.4.Parse input from Form
24.15.5.JSTL Form Error Check and Forward
24.15.6.Use JSTL to Create URL From Form Input
24.15.7.Check Parameter Value and Output Error Message