Ø 配置步骤:
1、 新建web项目,并在项目的web.xml中为项目添加Struts2支持,如下
<filter> <filter-name>struts2</filter-name> <filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class> </filter <filter-mapping> <filter-name>struts</filter-name> <url-pattern>/*<url-pattern> </filter-mapping>
2、 在lib文件夹下引入必要的类库
FrameMaker类库、ONGL类库、struts2core类库、xwork类库、common-logging类库
3、开发JSP及Action
4、在struts.xml文件中添加相应的Action 支持
<struts>
<package name=”struts” extends=”struts-default”>
<action name=”login” class=”com.text.LoginAction”>
<result name=”success”>result.jsp</result>
</action>
</package>
</struts>
小技巧,部署Web项目中可以在Tomcat的Servlet.xml中加入如下标签,在Tomcat发现项目中有修改类文件、xml文件等时自动重启更新文件,可以在开发过程中省去频繁重启服务器的麻烦。
<Context path=”/struts2” docBase=”d:\workspace\projectName\WebRoot” reloadable=”true”/>
本文介绍了如何在Web项目中配置Struts2框架,包括在web.xml中添加过滤器、引入必要的类库、开发JSP及Action以及在struts.xml中配置Action等内容。通过一个小技巧,还介绍了如何设置Tomcat自动重启,提高开发效率。

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



