8:07 am - Friday March 24, 2017

Struts 2 Datepicker Example and Tutorial

CANDID INDUSTRIAL TRAINING -- CHENNAI
Corporate Training for Experienced Candidate
Struts | Hibernate | Spring | Java / J2EE
SOAP | RestFull | Design Pattern | more...
Ph: +91 72000 69003
137b, 2nd st, shanthi nagar, Chrompet, Chennai -600044

BACK

 Struts 2  Datepicker Example and Tutorial

Datepicker.java


package com.candidjava.controller;

import com.opensymphony.xwork2.ActionSupport;

public class Datepicker extends ActionSupport {
	private static final long serialVersionUID = 1L;

	private String dob;

	public String getDob() {
		return dob;
	}

	public void setDob(String dob) {
		this.dob = dob;
	}

	public String execute() {
		return SUCCESS;

	}

}

struts.xml


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

<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">

<struts>
<include file="struts-default.xml"/>
<package name="a" extends="struts-default">
<action name="datepicker">
<result name="success">/success.jsp</result>
</action>
</package>
</struts>

&nbsp;

web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>

index.jsp


<%@ taglib prefix="s" uri="/struts-tags"%>
<html>
<head>
<s:head theme="ajax" />
</head>
<body>
	<h4>
		<u>Struts2 Datepicker example</u>
	</h4>
	<s:form action="datepicker">
		<s:datetimepicker label="Date of Birth" name="dob"
			displayFormat="dd-MMM-yyyy" required="true" />
		<s:submit value="Click" align="center" />

	</s:form>

</body>
</html>

success.jsp


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

Your Date of Birth is
<b><s:property value="dob" />,</b>
<br />

Output Screenshots:

                         Download  Sourcecode

BACK

Filed in: Z-A All Java Codes

Comments are closed.