1. 从 官网 http://struts.apache.org 下载 struts 的开发包(struts-2.3.8-all.gz)
2.利用winrar 软件把下载下来的包解压开,struts-2.3.8,解压之后有四个文件夹,分别是 apps ,docs,lib ,src
3.在MyEclipse 中新建一个Javaweb 项目(project ---->MyEclipse---->Java Enterprise projects---->web project)
4.把apps 文件下的struts2-blank.war解压开,从WEB-INF----->classes下把struts.xml 文件拷贝到新建工程的src目录下
为了测试简单把struts.xml 中package 标签修改为如下:
<constant name="struts.devMode" value="true" /> //默认value的值为false,改为true可以对当前.jsp进行修改,而不需要重启服务器
<package name="default" namespace="/" extends="struts-default">
<action name="hello">
<result>
/index.jsp
</result>
</action>
</package>
5.把 WEB-INF--->lib下所有.jar包拷贝到工程目录下的lib目录下
6.把 WEB-INF 下 web.xml 中的
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
这段代码拷贝到工程目录下web.xml 中,然后启动tomcat 服务器 运行 :http://localhost:8080/Demo01/hello/ (Demo01 代表工程名,hello 代表action 的名称)
7.到此为止,第一个struts2项目的HelloStruts2 完成
8.如果.xml文件中没有提示的时候可以这样去修改 window----Preferences----Files and Editors----XML -----XML Catalog 点击add

key 里面要写入: http://struts.apache.org/dtds/struts-2.3.dtd
Location: 在你解压开的lib目录下找到 struts2-core-2.3.8.jar然后解压开,找找到 struts-2.3.dtd,最后的路径为:E:\开发资料\MyEclipse demo\struts-2.3.8\lib\struts-2.3.dtd
9.struts 的作用:把请求与视图分开
本文详细介绍了如何使用Struts2框架搭建第一个项目,包括下载安装包、配置项目环境、设置核心配置文件struts.xml及部署应用程序等步骤。
422

被折叠的 条评论
为什么被折叠?



