1)创建index.jsp作为输入
该jsp页面使用struts UI标记创建表单。它从用户那里接收名称, 密码和电子邮件ID。
index.jsp
<%@ taglib prefix="s" uri="/struts-tags" %>
<%@ taglib prefix="sx" uri="/struts-dojo-tags" %>
<html>
<head>
<sx:head />
</head>
<body>
<s:form action="DateTimePicker" method="POST">
<sx:datetimepicker name="todayDate" label="Format (yyyy-mm-dd)" displayFormat="yyyy-MM-dd"/>
<sx:datetimepicker name="todayDate2" label="Format (dd-mm-yyyy)" displayFormat="dd-MMM-yyyy"/>
<s:submit></s:submit>
</s:form>
</body>
</html>
2)创建动作类
该操作类继承了ActionSupport类, 并覆盖了execute方法。
RegisterAction.java
package mypack;
import com.opensymphony.xwork2.ActionSupport;
import java.util.Date;
public class DateBean extends ActionSupport {
private Date todayDate, todayDate2;
public Date getTodayDate2() {
return todayDate2;
}
public void setTodayDate2(Date todayDate2) {
this.todayDate2 = todayDate2;
}
public Date getTodayDate() {
return todayDate;
}
public void setTodayDate(Date value) {
todayDate = value;
}
public String execute(){
return SUCCESS;
}
}
3)创建struts.xml
该xml文件通过名称输入和拦截器jsonValidatorWorkflowStack定义了一个额外的结果。
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="s" extends="struts-default">
<action name="DateTimePicker" class="mypack.DateBean">
<result>/welcome.jsp</result>
</action>
</package>
</struts>
4)创建视图组件
它是显示用户信息的简单jsp文件。
welcome.jsp
<%@ taglib prefix="s" uri="/struts-tags" %>
first date:<s:property value="todayDate" />
second date:<s:property value="todayDate2" />
下载此示例
评论前必须登录!
注册