工程名:strutsdemo,在配置struts.xml中,主要在package里面加入namespace="****",見例子2。
1、
1
<?xml version="1.0" encoding="GBK"?>
2
2<!DOCTYPE struts PUBLIC
3
3 "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
4
4 "http://struts.apache.org/dtds/struts-2.0.dtd">
5
5<struts>
6
6
7
7 <package name="org" extends="struts-default">
8
8 <action name="login" class="org.LoginAction">
9
9 <result name="input">/login.jsp</result>
10
10 <result name="error">/error.jsp</result>
11
11 <result name="success">/welcome.jsp</result>
12
12 </action>
13
13 <action name="getUsers" class="org.GetUsersAction">
14
14 <result name="login">/login.jsp</result>
15
15 <result name="success">/listUsers.jsp</result>
16
16 </action>
17
17 </package>
18
18</struts>

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

可以通過http://localhost:8080/strutsdemo/getUsers.action訪問
2、
1
<?xml version="1.0" encoding="GBK"?>
2
<!DOCTYPE struts PUBLIC
3
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
4
"http://struts.apache.org/dtds/struts-2.0.dtd">
5
<struts>
6
7
8
9
<package name="org" extends="struts-default">
10
<action name="login" class="org.LoginAction">
11
<result name="input">/login.jsp</result>
12
<result name="error">/error.jsp</result>
13
<result name="success">/welcome.jsp</result>
14
</action>
15
</package>
16
17
<package name="get" extends="struts-default" namespace="/apple">
18
<action name="getUsers" class="org.GetUsersAction">
19
<result name="login">/login.jsp</result>
20
<result name="success">/listUser.jsp</result>
21
</action>
22
</package>
23
</struts>
可以通過http://locahost:8080/strutsdemo/apple/getUsers.action 訪問
2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

例子1是沒有指定命名空間的屬性,默認命名空間為空,例子2有命名空間apple。
-------------------------------------------------------------------------------------------------
PS:本博客文章,如果沒有注明是有“轉”字樣,屬于本人原創。如果需要轉載,務必注明作者和文章的詳細出處地址,否則不允許轉載,多謝合作!