struts2 标签

action

 

 

 

package com.jin;

 

import java.util.Date;

 

import com.opensymphony.xwork2.ActionSupport;

 

public class PersonAction extends ActionSupport {

private Date date = new Date();

 

public Date getDate() {

return date;

}

 

public void setDate(Date date) {

this.date = date;

}

 

public String show() {

return SUCCESS;

}

}

 

可以在资源文件PersonAction.properties里定义一个日期的格式

 

format.time = {0,time}

format.number = {0,number,#0.0##}

format.percent = {0,number,##0.00'%'}

format.money = {0,number,\u00A4##0.00}

format.date = {0,date,MM/dd/yyyy}

 

 

struts.xml里定义一个action

 

 

<struts>

    <package name="my" extends="struts-default">  

            <!-- 使用Annotation配置校验的Action -->  

            <action name="personAction_*" class="com.jin.PersonAction" method="{1}">  

                <result name="success">/index.jsp</result>  

            </action>  

        </package>  

</struts>    

  在index.jsp里使用

   <s:text name="format.date">

       <s:param value="date"/>

    </s:text>

 

 参考资料http://struts.apache.org/2.1.8/docs/formatting-dates-and-numbers.html

               http://struts.apache.org/2.1.8/docs/localization.html

 

你可能感兴趣的:(struts2)