Struts 2 datetimepicker Example

Struts » on Oct 25, 2011 { 17 Comments } By Sivateja

Let us see how to work with this datetimepicker in struts 2, actually no need to add any external jar files to work with this,  some of us may think we need to add some Ajax related jars bla bla…,  let me clear

jars required

  • commons-logging-1.0.4.jar
  • freemarker-2.3.8.jar
  • ognl-2.6.11.jar
  • struts2-core-2.0.11.jar
  • xwork-2.0.4.jar

Let us see one example, files required

  • index.jsp
  • success.jsp
  • web.xml
  • struts.xml

Directory Structure


<%@ taglib prefix="s" uri="/struts-tags" %>

  <s:head theme="ajax" debug="true"/>

 <s:form action="resultAction">

 <s:datetimepicker label="Select From" name="toDate" displayFormat="MM-dd-yy" required="true" />
 <s:datetimepicker label="Select To" name="fromDate" displayFormat="MM-dd-yy" required="true" />
 <s:datetimepicker label="Select Other" name="otherDate" displayFormat="MM-dd-yy" required="true" />
 <s:submit value="Click" align="center" />




<%@ taglib prefix="s" uri="/struts-tags" %>

 Entered to date:  <s:property value="toDate"/><br>
 Entered from date:  <s:property value="fromDate"/><br>
 Entered other date:  <s:property value="otherDate"/><br>

package java4s;
import java.util.Date;
public class LogingEx{
    private static final long serialVersionUID = 1L;

    private Date toDate;
    private Date fromDate;
    private Date otherDate;

    public Date getToDate() {
        return toDate;
    public void setToDate(Date toDate) {
        this.toDate = toDate;

    public Date getFromDate() {
        return fromDate;
    public void setFromDate(Date fromDate) {
        this.fromDate = fromDate;

    public Date getOtherDate() {
        return otherDate;
    public void setOtherDate(Date otherDate) {
        this.otherDate = otherDate;

      public String execute(){
      return "success";



<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="" xmlns="" xmlns:web="" xsi:schemaLocation="" id="WebApp_ID" version="2.5">


<?xml version="1.0" encoding="UTF-8"?>

"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"

    <include file="struts-default.xml"/>
    <package name="a" extends="struts-default">
        <action name="resultAction" class="java4s.LogingEx">
            <result name="success">/success.jsp</result>
            <result name="error">/error.jsp</result>

After Execution



You Might Also Like

  ::. About the Author .::

Sivateja Kandula - Java/J2EE Full Stack Developer
Founder of Java4s - Get It Yourself, A popular Java/J2EE Programming Blog, Love Java and UI frameworks.
You can sign-up for the Email Newsletter for your daily dose of Java tutorials.


17 Responses to “Struts 2 datetimepicker Example”
  1. abhishek says:

    i am using date picker in struts 2 . i have to print error message when one try to give from date is greater than to date.

  2. Java4s says:


    You can get this by using XML Validations.

    But i will prefer jQuery validations for these type of tasks 🙂 as easy and less time taking, try this too.

  3. Veera says:

    How to validate the datetimepisker in struts 2….? and How to store this value to database….? Whenever i try to validate using requiredstring and date then give any value in appropriate form, the value is null, mean the validation show “date is required”.Sometimes i try remove validation and store the value to database, the value is store successfully but not store appropriate value, whenever i try to store different value but always store “null”….Please help anyone…..

    Thanks in advance

    Best regards

  4. Eve says:

    Can the datepicker be used with tiles?

  5. nagappa says:

    With Jquery we can only do client-side validations and using xml files we are doing server-side validations but is ia better do both validations as many people can edit html with firebug and can click on submit

  6. anjali says:


    I am trying to use above code but i am not getting any textfield or calender to insert date.
    Please let me know need to be done

  7. Aashish says:

    How to remove Time from DateTimePicker while inserting Date into Database?

  8. Hi,

    Here in file, you didnt extend the ActionSupport class, but you have wrote the execute method. Is it possible?? if Yes, why you didnt use the ActionSupport class here. Please explain.

  9. Hi ,
    If i use characters in that it changes to default date 01/01/70.
    how to change that date as current date??

  10. sonia says:

    In newer version there is no datatimepicker that is in strut-core jar, den what to do?

  11. Susan says:

    show unknown tag in my jsp file. How can I solve that?

  12. MANIKANT says:

    Sir ,
    how i set range of year in this calendar??

  13. Pakku says:


    Can we use onclik() , onChange() events in datetimepicker?

  14. S.Amaranath says:

    How to use multiple submit buttons in same jsp page

  15. pradeep says:

    am getting null in struts action class why

  16. Raj says:

    HI Brother!

    Your tutorial is very helpful for me. i found one small missing on the above class you missed to “extends ActionSupport”. please fix this brother..,

  17. Krishna says:

    Brother,i am not getting calender to pick date&month,can i know the solution.


By posting your answer, you agree to our comments policy.
Most Recent Posts from Top Categories
Spring Boot Hibernate Spring
Contact | About Us | Privacy Policy | Advertise With Us

© 2010 - 2024 Java4s - Get It Yourself.
The content is copyrighted to Sivateja Kandula and may not be reproduced on other websites.