In this example, you will see the implementation of date tag of struts2.2.1. Date tag is used to output the date object into the required format.
1- index.jsp
<html>ADS_TO_REPLACE_1 <head><title>Struts2.2.1_Date_Tag_Example</title></head> <body> <h2>Struts2.2.1_Date_Tag_Example.</h2><hr>Current dateADS_TO_REPLACE_2 <a href="CurrenDate.action">Current date</a> <hr> Date in different format <a href="CurrenDateInDiffFormat.action">CurrenDateInDiffFormat</a>ADS_TO_REPLACE_3 </body> </html> |
2-DateAction.java
package roseindia.action; |
3-CurrentDate.jsp ADS_TO_REPLACE_4
<%@taglib uri="/struts-tags" prefix="s" %> <html> <head><title>Struts2.2.1_Date_Tag_Example</title>ADS_TO_REPLACE_5 </head><body> <h2>Struts2.2.1_Date_Tag_Example.</h2><hr> Current Date :ADS_TO_REPLACE_6 <s:date name="currentDate" format="yyyy-MM-dd"></s:date> </body> </html> |
4_struts.xml
<struts>ADS_TO_REPLACE_7 <constant name="struts.enable.DynamicMethodInvocation" value="false" /> <constant name="struts.devMode" value="false" /> <package name="roseindia" extends="struts-default" namespace="/" >ADS_TO_REPLACE_8 <action name="CurrenDate" class="roseindia.action.DateAction"> <result name="success">/jsp/CurrentDate.jsp</result> </action>ADS_TO_REPLACE_9 <action name="CurrenDateInDiffFormat" class="roseindia.action.DateAction"> <result name="success">/jsp/DateInDifferentFormat.jsp</result> </action>ADS_TO_REPLACE_10 </package> </struts> |
5_DateInDifferentFormat.jsp
<%@ taglib uri="/struts-tags" prefix="s" %> <html>ADS_TO_REPLACE_11 <head><title>Struts2.2.1_Date_Tag_Example </title> <STYLE type="text/css"> b{color: maroon;}ADS_TO_REPLACE_12 </STYLE></head> <body> <h2>Struts2.2.1_Date_Tag_Example.</h2><hr>ADS_TO_REPLACE_13 <b>Date Format(EEEE yyyy-MM-dd):</b><br/><br/> <s:date name="pastDate" format="EEEE yyyy-MM-dd" /><hr> <b>Date Format (EEEE MM/dd/yyyy hh:mm AM/PM):</b><br/><br/>ADS_TO_REPLACE_14 <s:date name="pastDate" format="EEEE MM/dd/yyyy 'at' hh:mm a" /><hr> <b>Date Format (EEEE dd-MMM-yyyy hh:mm AM/PM) :</b><br/><br/> <s:date name="pastDate" format="EEEE dd-MMM-yyyy 'at' hh:mm a" /><hr>ADS_TO_REPLACE_15 <b> Format (EEEE dd/MM/yyyy hh:mm) :</b><br/><br/> <s:date name="pastDate" format="EEEE dd/MM/yyyy hh:mm" /><hr> <b>Date Format(Nice):</b><br/><br/>ADS_TO_REPLACE_16 <s:date name="pastDate" format="yyyy-MM-dd" nice="true"/><hr> </body> </html> |
index.jspADS_TO_REPLACE_17
currentDate.jsp
ADS_TO_REPLACE_18
StrutsExample.gif
Download Select Source CodeADS_TO_REPLACE_19
Advertisements
Ads
Ads