3步配置Struts2

开始学习Struts2喽。Struts2与Strust1的配置方式几乎完全不同。先从struts.apache.org上下载了最新的struts2-2.1.6,由于目前还没有什么IDE支持Struts2,所以只能自己手工配置了。不过我也喜欢手工配置,什么东西都由工具来生成没有什么意思,脱离了工具就成白痴了。

第一步,导包。下载下来的jar包并不是全都要,只需要下面这6个包即可。

1.commons-logging-1.0.4.jar

2.commons-fileupload-1.2.1.jar

3.freemarker-2.3.13.jar

4.ognl-2.6.11.jar

5.struts2-core-2.1.6.jar

6.xwork-2.1.2.jar

以上6个包,缺一不可。

第二步,修改web.xml。增加如下配置:

[xml]
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
[/xml]

第三步,增加struts.xml文件。在struts1中,我们配置ActionForm及Action时是在strust-config.xml中,而在struts2中则是在struts.xml中,且该文件必须位于WEB-INF\classes目录下。

[xml]
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.1//EN"
"http://struts.apache.org/dtds/struts-2.1.dtd">
<struts>
<package name="struts2" extends="struts-default">
</package>
</struts>
[/xml]

经过上面这三步,Struts2就已经基本配置完成了。


除非另有声明,本站遵循【署名-非商业性使用-相同方式共享 3.0 共享协议】授权。

转载原创文章请注明,转载自:Neeke[http://www.ineeke.com]

本文链接: http://www.ineeke.com/archives/settingmystruts2/

2009年3月3日 | 归档于 J2EE技术 | 1 条评论
标签: ,
  1. 三少
    2009年3月3日 21:06 | #1

    呵呵 还要配置action呢

    Gravatar头像neeke 于 2009-3-4 23:18:25 回复

    嗯,我知道,我这里说的是基本的配置嘛,我觉得action的配置已经到开始应用开发了。

发表评论

XHTML: 您可以使用这些标签: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">
n:-zy n:-zr n:-zan n:-xf n:-wx n:-tz n:-tt n:-ts n:-sy n:-st n:-ss n:-sk n:-qd n:-pz n:-lh n:-kun n:-ku n:-hx n:-hd n:-gt n:-gg n:-bz

NOTICE: You should type some Chinese word (like “你好”) in your comment to pass the spam-check, thanks for your patience!