User:
package com.example.struts.domain;
import java.util.Date;
public class User {
private String username;
private String password;
private Date date;
private Integer age;
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 getDate() {
return date;
}
public void setDate(Date date) {
this.date = date;
}
public Integer getAge() {
return age;
}
public void setAge(Integer age) {
this.age = age;
}
@Override
public String toString() {
return "User{" +
"username='" + username + '\'' +
", password='" + password + '\'' +
", date=" + date +
", age=" + age +
'}';
}
}
Action:
package com.example.struts;
import com.example.struts.domain.User;
import com.opensymphony.xwork2.Action;
public class UserAction implements Action {
private User user;
private String code;
public String getCode() {
return code;
}
public void setCode(String code) {
this.code = code;
}
public User getUser() {
return user;
}
public void setUser(User user) {
this.user = user;
}
@Override
public String execute() throws Exception {
System.out.println(this.user);
System.out.println(this.code);
return NONE;
}
}
jsp:
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>用户信息</title>
</head>
<body>
<form method="post" action="${ pageContext.request.contextPath }/user/add1">
<input type="text" name="user.username" />
<input type="password" name="user.password" />
<input type="number" name="user.age" />
<input type="date" name="user.date" />
<input type="text" name="code" />
<button type="submit">提交</button>
</form>
</body>
</html>
struts.xml:
<constant name="struts.enable.SlashesInActionNames" value="true"/>
<action name="user/add1" class="com.example.struts.UserAction">
</action>
来源:oschina
链接:https://my.oschina.net/u/3870422/blog/4313038