Date tag example in struts2 framework
Previous | Home | Next |
Struts2 framework provide date tag to give the date format on the browser.<s:date name="" format="" />
Struts2 framework provide following date tag ,<s:date name="date" format="dd/MM/yyyy" />
Directory Structure of <s:date> tag Example in Struts 2.0 Using MyEclipse IDEindex.jsp<%@ taglib prefix="s" uri="/struts-tags" %> <h1>Date tag example in struts2 framework</h1> Date and Time:- <strong><s:date name="date" /></strong> <br/> Date format in "dd/MM/yyyy":- <s:date name="date" format="dd/MM/yyyy" />web.xml<?xml version="1.0" encoding="UTF-8"?> <web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"> <filter> <filter-name>f1</filter-name> <filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class> </filter> <filter-mapping> <filter-name>f1</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> </web-app>struts.xml<?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN" "http://struts.apache.org/dtds/struts-2.1.dtd"> <struts> <package name="demo" extends="struts-default"> <action name="" class="org.r4r.DateTagAction"> <result name="success" type="dispatcher">/index.jsp</result> </action> </package> </struts>DateTagAction.javapackage org.r4r; import java.util.Calendar; import java.util.Date; public class DateTagAction { Date date; public String execute(){ Calendar cal=Calendar.getInstance(); cal.set(2011, 06, 9); Date setTime=cal.getTime(); setDate(setTime); return "success"; } public Date getDate() { return date; } public void setDate(Date date) { this.date = date; } }Output
Previous | Home | Next |