标签:登录 oid 路径 extends alt 日期 添加 html 4.01 不能
package com.djoker.struts2; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; import java.util.Map; import org.apache.struts2.util.StrutsTypeConverter; public class DateConverter extends StrutsTypeConverter{ private static final String pattern = "yyyy/MM/dd"; @Override public Object convertFromString(Map context, String[] values, Class toClass) { String dateStr = values[0]; Date date = null; try { date = new SimpleDateFormat(pattern).parse(dateStr); } catch (ParseException e) { e.printStackTrace(); } return date; } @Override public String convertToString(Map context, Object o) { Date date = (Date)o; String dateStr = new SimpleDateFormat("yyyy年MM月dd日").format(date); return dateStr; } }
package com.djoker.struts2; import java.util.Date; import org.apache.struts2.ServletActionContext; import com.opensymphony.xwork2.Action; public class UserAction { private String username; private String password; private Date createDate; public String getUsername() { return username; } public void setUsername(String username) { this.username = username; } public String getPassword() { return password; } public void setPassword(String password) { this.password = password; } public Date getCreateDate() { return createDate; } public void setCreateDate(Date createDate) { this.createDate = createDate; } public String addUser() throws Exception { ServletActionContext.getRequest().setAttribute("username", username); ServletActionContext.getRequest().setAttribute("password", password); ServletActionContext.getRequest().setAttribute("createDate", createDate); return Action.SUCCESS; } }
<%@ page language="java" contentType="text/html; charset=GB18030" pageEncoding="GB18030"%> <%@ taglib uri="/struts-tags" prefix="s"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=GB18030"> <title>Insert title here</title> </head> <body> <h1>登录成功</h1> ${msg }<br> ${username }<br> ${password }<br> ${createDate }<br> <s:property value="createDate"/> </body> </html>
最终演示效果
标签:登录 oid 路径 extends alt 日期 添加 html 4.01 不能
原文地址:http://www.cnblogs.com/djoker/p/6219063.html