Skip to content

Commit f71023a

Browse files
committed
Mode
1 parent 6b09fab commit f71023a

File tree

8 files changed

+117
-7
lines changed

8 files changed

+117
-7
lines changed

WebContent/index.jsp

+6-1
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,13 @@
4545
<a href="<%=context%>/actions/Course_delete">删除课程</a>
4646
<br />通配符结束ActionWildcard
4747
<br>
48+
<br />ActionAttrParamInput开始 使用action属性接收参数 和ActionMethod开始
49+
<br>使用action属性接收参数
50+
<a href="user/user!add?name=a&age=8">添加用户</a>
51+
<br />ActionAttrParamInput结束使用action属性接收参数
52+
<br>
53+
使用Domain Model接收参数<a href="user/user!add?user.name=a&user.age=8">添加用户</a>
4854

49-
<p>Loading ...</p>
5055

5156
</body>
5257
</html>

WebContent/user_add.jsp

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
77
<title>Insert title here</title>
88
</head>
9-
<body>User Add Success!
9+
<body>
10+
User Add Success!
1011
</body>
1112
</html>

WebContent/user_add_success.jsp

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
77
<title>Insert title here</title>
88
</head>
9-
<body>User Add Success!
9+
<body>
10+
User Add Success!
1011
</body>
1112
</html>

build/classes/struts.xml

+2-2
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@
7474
</package>
7575
<!-- path结束 -->
7676

77-
<!-- ActionMethod开始 -->
77+
<!-- ActionMethod开始 ActionAttrParamInput -->
7878
<package name="user" extends="struts-default" namespace="/user">
7979
<action name="userAdd" class="com.struts2.front.action.UserAction"
8080
method="add">
@@ -88,7 +88,7 @@
8888
</result>
8989
</action>
9090
</package>
91-
<!-- ActionMethod结束 -->
91+
<!-- ActionMethod结束 ActionAttrParamInput -->
9292

9393
<!-- 通配符开始 ActionWildcard -->
9494
<package name="actions" extends="struts-default" namespace="/actions">

src/com/struts2/front/action/UserAction.java

+34
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,47 @@
1515
package com.struts2.front.action;
1616

1717
import com.opensymphony.xwork2.ActionSupport;
18+
import com.struts2.front.model.User;
1819

1920
/**
2021
* @filename 文件名称:UserAction.java
2122
* @contents 内容摘要:
2223
*/
2324
public class UserAction extends ActionSupport {
25+
private String name;
26+
private int age;
27+
28+
public String getName() {
29+
return name;
30+
}
31+
32+
public void setName(String name) {
33+
this.name = name;
34+
}
35+
36+
public int getAge() {
37+
return age;
38+
}
39+
40+
public void setAge(int age) {
41+
this.age = age;
42+
}
43+
44+
private User user;
45+
46+
public User getUser() {
47+
return user;
48+
}
49+
50+
public void setUser(User user) {
51+
this.user = user;
52+
}
53+
2454
public String add() {
55+
// System.out.println("name:" + name);
56+
// System.out.println("age:" + age);
57+
// System.out.println("name:" + user.getName());
58+
// System.out.println("age:" + user.getAge());
2559
return SUCCESS;
2660
}
2761

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*************************************************************************************************
2+
* 版权所有 (C)2015
3+
*
4+
* 文件名称:UserDTO.java
5+
* 内容摘要:UserDTO.java
6+
* 当前版本:TODO
7+
* 作 者:李加蒙
8+
* 完成日期:2016年8月16日 下午5:30:27
9+
* 修改记录:
10+
* 修改日期:2016年8月16日 下午5:30:27
11+
* 版 本 号:
12+
* 修 改 人:
13+
* 修改内容:
14+
************************************************************************************************/
15+
package com.struts2.front.dto;
16+
/**
17+
@filename 文件名称:UserDTO.java
18+
@contents 内容摘要:
19+
*/
20+
public class UserDTO {
21+
22+
}
23+

src/com/struts2/front/model/User.java

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*************************************************************************************************
2+
* @版权所有 (C)2015, 星火工作室
3+
*
4+
* @文件名称:User.java
5+
* @内容摘要:用户bean
6+
* @当前版本: TODO
7+
* @作 者: 李加蒙
8+
* @完成日期:2015年9月20日 下午6:25:05
9+
* @修改记录:
10+
* @修改日期:2015年9月20日 下午6:25:05
11+
* @版 本 号:
12+
* @修 改 人:
13+
* @修改内容:
14+
************************************************************************************************/
15+
16+
package com.struts2.front.model;
17+
18+
import java.io.Serializable;
19+
20+
/**
21+
* @filename 文件名称:User.java
22+
* @contents 内容摘要:用户注册bean
23+
*/
24+
public class User implements Serializable {
25+
26+
private static final long serialVersionUID = 1L;
27+
28+
private String name;
29+
private int age;
30+
31+
public String getName() {
32+
return name;
33+
}
34+
35+
public void setName(String name) {
36+
this.name = name;
37+
}
38+
39+
public int getAge() {
40+
return age;
41+
}
42+
43+
public void setAge(int age) {
44+
this.age = age;
45+
}
46+
}

src/struts.xml

+2-2
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@
7474
</package>
7575
<!-- path结束 -->
7676

77-
<!-- ActionMethod开始 -->
77+
<!-- ActionMethod开始 ActionAttrParamInput -->
7878
<package name="user" extends="struts-default" namespace="/user">
7979
<action name="userAdd" class="com.struts2.front.action.UserAction"
8080
method="add">
@@ -88,7 +88,7 @@
8888
</result>
8989
</action>
9090
</package>
91-
<!-- ActionMethod结束 -->
91+
<!-- ActionMethod结束 ActionAttrParamInput -->
9292

9393
<!-- 通配符开始 ActionWildcard -->
9494
<package name="actions" extends="struts-default" namespace="/actions">

0 commit comments

Comments
 (0)