天天看点

配置struts2 Helloworld

我用到是myeclipse10 ,struts的版本不一样所要导入到包也不同

各版本struts所需导入的包

struts-2.0 所必需的jar包

1.commons-logging----.jar

2.struts-core----.jar

3.xwork----.jar

4.ognl----.jar

5.freemarker----.jar

struts-2.1.6 所必需的jar包

1.commons-fileupload----.jar

2.commons-logging----.jar

3.struts-core----.jar

4.xwork----.jar

5.ognl----.jar

6.freemarker----.jar

struts-2.3.4.1所必需的

7.commons-lang3----jar

8.javassist----.GA.jar

9.commons-io------.jar

10.commons-lang-----.jar

我这里struts的版本是:struts-2.3.4.1

1、首先将struts2 所要用到到10个包加到所建到web项目到lib目录下

2、建一个helloworld.jsp

3、然后在src下建一个包:com.test.action ,并建一个类:HelloWorld.java

4、然后在src下新建一个配置文件:struts.xml  注意:名字一定是:struts.xml

配置struts.xml 首先把dtd信息加载上

在struts-2.3.4.1-all\struts-2.3.4.1\apps目录下有5个war格式的文件

随便解压一个,里面都有struts.xml文件,将该文件的开头部分直接copy过来即可

5、配置web.xml文件     用的是过滤器的思想

6、启动服务器运行

访问:http://localhost:8088/StrutsTest/helloworld.action  即可

配置完成

继续阅读