Struts 2 日期处理

1.日期格式化

demo1

<s:textfield name="contact.birthDate" label="ContactBirthDate">
	<s:param name="value">
		<s:date name="contact.birthDate" format="yyyy-MM-dd" />
	</s:param>
</s:textfield>

 

 

demo2

<input type="text" value="<s:date name="contact.birthDate" format="yyyy-MM-dd" />" />
 

 

2.使用日期控件

加入struts2-dojo-plugin

......
	<dependency>
		<groupId>org.apache.struts</groupId>
		<artifactId>struts2-dojo-plugin</artifactId>
		<version>${struts-version}</version>
	</dependency>
......

To use this tag:

  • Add: <%@ taglib prefix="sx" uri="/struts-dojo-tags" %> to your page.
  • The head tag must be included on the page, which can be configured for performance or debugging purposes.
  • If the parseContent parameter for the head tag is false (it is false by default), then the id tag is required.

 

<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib uri="/struts-tags" prefix="s"%>
<%@ taglib prefix="sx" uri="/struts-dojo-tags"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<sx:head/>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Save Contact</title>
<script type="text/javascript" src="scripts/jquery-1.7.2.min.js"></script>
<script type="text/javascript">
	
</script>
</head>
<body>
	<div align="center">
		<h1>
			<font color="red">Save Contact</font>
		</h1>

		<s:form action="saveContact">
			<s:textfield name="contact.firstName" label="ContactFirstName"></s:textfield>
			<s:textfield name="contact.lastName" label="ContactLastName"></s:textfield>
			<sx:datetimepicker name="contact.birthDate" label="ContactBirthDate"
				displayFormat="yyyy-MM-dd"></sx:datetimepicker>
			<s:submit value="submit"></s:submit>
		</s:form>
	</div>
</body>
</html>
 


详细文档说明可以参考http://struts.apache.org/2.x/docs/datetimepicker.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值