struts 2的配置(版本2.3)

这个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的学习了。我也在进行着,有新进展我会传上来给大家的。



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值