Skip to content

Commit 6b09fab

Browse files
committed
通配符
1 parent 5cdd5a8 commit 6b09fab

9 files changed

+207
-10
lines changed

WebContent/Teacher_add_success.jsp

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<%@ page language="java" contentType="text/html; charset=UTF-8"
2+
pageEncoding="UTF-8"%>
3+
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
4+
<html>
5+
<head>
6+
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
7+
<title>teacher_add_success</title>
8+
</head>
9+
<body>
10+
<p>teacher_add_success!</p>
11+
</body>
12+
</html>

WebContent/Teacher_delete_success.jsp

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<%@ page language="java" contentType="text/html; charset=UTF-8"
2+
pageEncoding="UTF-8"%>
3+
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
4+
<html>
5+
<head>
6+
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
7+
<title>teacher_delete_success</title>
8+
</head>
9+
<body>
10+
teacher_delete_success!
11+
</body>
12+
</html>

WebContent/index.jsp

+21-8
Original file line numberDiff line numberDiff line change
@@ -15,22 +15,35 @@
1515
<title>页面未找到</title>
1616
</head>
1717
<body>
18-
路径问题path开始
18+
<br /> 路径问题path开始
1919
<br>
2020
<a href="path/path.action">路径问题</a>
21-
<br> 路径问题path结束
21+
<br /> 路径问题path结束
2222
<br>
23-
<br> ActionMethod开始
23+
<br /> ActionMethod开始
2424
<br> Action执行的时候并不一定要执行execute方法
25-
<br /> 可以在配置文件中配置Action的时候用method=来指定执行哪个方法
25+
<br> 可以在配置文件中配置Action的时候用method=来指定执行哪个方法
2626
也可以在url地址中动态指定(动态方法调用DMI)(推荐)
27-
<br />
27+
<br>
2828
<a href="<%=context%>/user/userAdd">添加用户 不推荐</a>
29-
<br />
29+
<br>
3030
<a href="<%=context%>/user/user!add">添加用户 推荐动态DMI</a>
31-
<br /> 前者会产生太多的action,所以不推荐使用;但是使用之前把struts.xml里面一句话修改成为 constant
31+
<br> 前者会产生太多的action,所以不推荐使用;但是使用之前把struts.xml里面一句话修改成为 constant
3232
name="struts.enable.DynamicMethodInvocation" value="true"
33-
<br> ActionMethod结束
33+
<br /> ActionMethod结束
34+
<br>
35+
<br />通配符开始 ActionWildcard
36+
<br> 使用通配符,将配置量降到最低
37+
<br>
38+
<a href="<%=context%>/actions/Studentadd">添加学生</a>
39+
<a href="<%=context%>/actions/Studentdelete">删除学生</a>
40+
<br> 不过,一定要遵守"约定优于配置"的原则
41+
<br>
42+
<a href="<%=context%>/actions/Teacher_add">添加老师</a>
43+
<a href="<%=context%>/actions/Teacher_delete">删除老师</a>
44+
<a href="<%=context%>/actions/Course_add">添加课程</a>
45+
<a href="<%=context%>/actions/Course_delete">删除课程</a>
46+
<br />通配符结束ActionWildcard
3447
<br>
3548

3649
<p>Loading ...</p>

WebContent/studentadd_success.jsp

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<%@ page language="java" contentType="text/html; charset=UTF-8"
2+
pageEncoding="UTF-8"%>
3+
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
4+
<html>
5+
<head>
6+
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
7+
<title>studentadd_success</title>
8+
</head>
9+
<body>
10+
studentadd_success!
11+
</body>
12+
</html>

WebContent/studentdelete_success.jsp

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<%@ page language="java" contentType="text/html; charset=UTF-8"
2+
pageEncoding="UTF-8"%>
3+
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
4+
<html>
5+
<head>
6+
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
7+
<title>studentdelete_success</title>
8+
</head>
9+
<body>
10+
studentdelete_success!
11+
</body>
12+
</html>

build/classes/struts.xml

+36-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
</action>
3030
</package>
3131

32-
<!-- namespace -->
32+
<!-- namespace开始 -->
3333
<package name="front" extends="struts-default" namespace="/front">
3434
<action name="namespace">
3535
<result>
@@ -46,6 +46,7 @@
4646
</result>
4747
</action>
4848
</package>
49+
<!-- namespace结束 -->
4950

5051
<!-- action开始 -->
5152
<package name="action" extends="struts-default" namespace="/">
@@ -89,5 +90,39 @@
8990
</package>
9091
<!-- ActionMethod结束 -->
9192

93+
<!-- 通配符开始 ActionWildcard -->
94+
<package name="actions" extends="struts-default" namespace="/actions">
95+
<action name="Student*" class="com.struts2.front.action.StudentAction"
96+
method="{1}">
97+
<result>
98+
/student{1}_success.jsp
99+
</result>
100+
</action>
101+
<action name="*_*" class="com.struts2.front.action.{1}Action">
102+
<result>
103+
/{1}_{2}_success.jsp
104+
</result>
105+
</action>
106+
</package>
107+
<!-- 通配符结束 ActionWildcard -->
92108

93109
</struts>
110+
111+
112+
113+
114+
115+
116+
117+
118+
119+
120+
121+
122+
123+
124+
125+
126+
127+
128+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*************************************************************************************************
2+
* 版权所有 (C)2015
3+
*
4+
* 文件名称:StudentAction.java
5+
* 内容摘要:StudentAction.java
6+
* 当前版本:TODO
7+
* 作 者:李加蒙
8+
* 完成日期:2016年8月16日 下午3:55:26
9+
* 修改记录:
10+
* 修改日期:2016年8月16日 下午3:55:26
11+
* 版 本 号:
12+
* 修 改 人:
13+
* 修改内容:
14+
************************************************************************************************/
15+
package com.struts2.front.action;
16+
17+
import com.opensymphony.xwork2.ActionSupport;
18+
19+
/**
20+
* @filename 文件名称:StudentAction.java
21+
* @contents 内容摘要:
22+
*/
23+
public class StudentAction extends ActionSupport {
24+
public String add() {
25+
System.out.println("sadd");
26+
return SUCCESS;
27+
}
28+
29+
public String delete() {
30+
System.out.println("sdelete");
31+
return SUCCESS;
32+
}
33+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*************************************************************************************************
2+
* 版权所有 (C)2015
3+
*
4+
* 文件名称:TeacherAction.java
5+
* 内容摘要:TeacherAction.java
6+
* 当前版本:TODO
7+
* 作 者:李加蒙
8+
* 完成日期:2016年8月16日 下午3:55:42
9+
* 修改记录:
10+
* 修改日期:2016年8月16日 下午3:55:42
11+
* 版 本 号:
12+
* 修 改 人:
13+
* 修改内容:
14+
************************************************************************************************/
15+
package com.struts2.front.action;
16+
17+
import com.opensymphony.xwork2.ActionSupport;
18+
19+
/**
20+
* @filename 文件名称:TeacherAction.java
21+
* @contents 内容摘要:
22+
*/
23+
public class TeacherAction extends ActionSupport {
24+
public String add() {
25+
System.out.println("tadd");
26+
return SUCCESS;
27+
}
28+
29+
public String delete() {
30+
System.out.println("tdelete");
31+
return SUCCESS;
32+
}
33+
}

src/struts.xml

+36-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
</action>
3030
</package>
3131

32-
<!-- namespace -->
32+
<!-- namespace开始 -->
3333
<package name="front" extends="struts-default" namespace="/front">
3434
<action name="namespace">
3535
<result>
@@ -46,6 +46,7 @@
4646
</result>
4747
</action>
4848
</package>
49+
<!-- namespace结束 -->
4950

5051
<!-- action开始 -->
5152
<package name="action" extends="struts-default" namespace="/">
@@ -89,5 +90,39 @@
8990
</package>
9091
<!-- ActionMethod结束 -->
9192

93+
<!-- 通配符开始 ActionWildcard -->
94+
<package name="actions" extends="struts-default" namespace="/actions">
95+
<action name="Student*" class="com.struts2.front.action.StudentAction"
96+
method="{1}">
97+
<result>
98+
/student{1}_success.jsp
99+
</result>
100+
</action>
101+
<action name="*_*" class="com.struts2.front.action.{1}Action">
102+
<result>
103+
/{1}_{2}_success.jsp
104+
</result>
105+
</action>
106+
</package>
107+
<!-- 通配符结束 ActionWildcard -->
92108

93109
</struts>
110+
111+
112+
113+
114+
115+
116+
117+
118+
119+
120+
121+
122+
123+
124+
125+
126+
127+
128+

0 commit comments

Comments
 (0)