Struts 2.0 起步
參考 http://www.aygfsteel.com/max/category/16130.html
1、添加struts2的jar包,struts2-core-2.x.x.jar, struts2-api-2.x.x.jar (struts2-all-2.x.x.jar即可,其他的struts2的插件包已經包含在里面)。
如添加其他的插件包,可能會出現文件重復,具體可以看異常信息。
或者不要加all包,而使用插件包,可以減小包的大小。
2、修改web.xml
1
<? xml version="1.0" encoding="UTF-8" ?>
2
< web-app version ="2.4"
3
xmlns ="http://java.sun.com/xml/ns/j2ee"
4
xmlns:xsi ="http://www.w3.org/2001/XMLSchema-instance"
5
xsi:schemaLocation ="http://java.sun.com/xml/ns/j2ee
6
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" >
7
< display-name > Struts2 Hello World! </ display-name >
8
9
< filter >
10
< filter-name > Struts2 </ filter-name >
11
< filter-class >
12
org.apache.struts2.dispatcher.FilterDispatcher
13
</ filter-class >
14
</ filter >
15
< filter-mapping >
16
< filter-name > Struts2 </ filter-name >
17
< url-pattern > /* </ url-pattern >
18
</ filter-mapping >
19
</ web-app >
20

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

3、在classpath下添加struts.properties文件,內容如下
struts.devMode = true
struts.enable.DynamicMethodInvocation = false
4、在classpath下添加struts.xml,這個是對應struts1.x里面的struts-config.xml
1
<! DOCTYPE struts PUBLIC
2
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
3
"http://struts.apache.org/dtds/struts-2.0.dtd" >
4
< struts >
5
< package name ="example" extends ="struts-default" >
6
< action name ="hello" class ="com.ivo.struts2.HelloWorld" method ="aliasAction" >
7
< result > /hello.jsp </ result >
8
</ action >
9
< action name ="Login" class ="com.ivo.struts2.Login" >
10
< result > /hello.jsp </ result >
11
</ action >
12
< action name ="LoginX" class ="com.ivo.struts2.LoginX" >
13
< result > /hello.jsp </ result >
14
</ action >
15
</ package >
16
</ struts >

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

注意,struts2的兩個相關文件需要放在classpath下
posted on 2006-12-29 10:09 風人園 閱讀(534) 評論(0) 編輯 收藏 所屬分類: Struts2