啊这个struts 2的配置,我是整整的忙了两天也是没有找到头绪,因为我感觉,做web开发的可控性真的不怎么强,因为它没有做应用、软件开发的那种可控,可调式的方式。一般卡住我们的都是因为我们第一次摸,连最基本的配置网页都不会。所以,这就很让人无奈。因为我们没有老师,只有自己拿书,自己找资料学习,而随着版本的更新,书上的配置已经远远不能满足自己了。下面自己介绍一下关于struts 2.3的配置。
首先,我们需要做的就是把struts需要的包导入进去,关于struts 2.3的包,最少应该导入的是:
接下来是配置web.xml,当然这里的filter-class可以是FilterDispacher也可以是StrutsPreparedAndExucuteFilter当然后者是最新的。具体参考如下:
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<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>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<login-config>
<auth-method>BASIC</auth-method>
</login-config>
</web-app>
如果不用最新的,控制台会输出:
***********************************************************************
* WARNING!!! *
* *
* >>> FilterDispatcher <<< is deprecated! Please use the new filters! *
* *
* This can be a source of unpredictable problems! *
* *
* Please refer to the docs for more details! *
* http://struts.apache.org/2.x/docs/webxml.html *
* *
***********************************************************************
接下来是struts.xml的配置了,这个是一定得配置好的,我第一次的时候就可能是struts.xml没有配置好,这里的版本是要严格和你导入的包匹配才可以的。上面我已经说了,我的版本号是2.3,所以配置文件如下,大家参考下:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
"http://struts.apache.org/dtds/struts-2.3.dtd">
<struts>
<package name="struts2">
<action name="query" class="com.QueryAction">
<result name="success">
/chapter7/success.jsp
</result>
<result>
/chapter7/error.jsp
</result>
</action>
</package>
</struts>
具体就是这么些配置文件了,剩下的就是你自己对struts的学习了。我也在进行着,有新进展我会传上来给大家的。