好得很程序员自学网

<tfoot draggable='sEl'></tfoot>

Struts2.5版本struts.xml与web.xml配置的更改方法

前言

升级之后的strut2技能总是会有点变化的,但是别忘记配置struts.xml与web.xml,下面话不多说了,来一起看看详细的介绍吧

1.web.xml核心过滤器的修改

?

1

2

3

4

5

6

7

8

9

10

11

12

13

14

<filter>

<filter-name>struts2</filter-name>

<filter- class >org.apache.struts2.dispatcher.filter.strutsprepareandexecutefilter</filter- class >

 

<!-- org.apache.struts2.dispatcher.ng.filter.strutsprepareandexecutefilter

 

之前的核心过滤器全类名会有个ng ,struts2. 5 核心过滤器没有这个

 

-->

</filter>

<filter-mapping>

<filter-name>struts2</filter-name>

<url-pattern>/*</url-pattern>

</filter-mapping>

2.struts.xml每个package需要增加如下配置

?

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

<global-allowed-methods>regex:.*</global-allowed-methods>

 

<?xml version= "1.0" encoding= "utf-8" ?>

<!doctype struts public

  "-//apache software foundation//dtd struts configuration 2.5//en"

  "http://struts.apache.org/dtds/struts-2.5.dtd" >

 

<struts>

<constant name= "struts.enable.dynamicmethodinvocation" value= "true" />

<constant name= "struts.devmode" value= "true" ></constant>

  < package name= "mypackage" namespace= "/" extends = "struts-default" >

   <global-allowed-methods>regex:.*</global-allowed-methods>

   <action name= "first" class = "useraction" >

   

    <result name= "success" >first.jsp</result>

    <result name= "add" >add.jsp</result>

    <result name= "delete" >delete.jsp</result>

   </action>

   

  </ package >

</struts>

3.struts.xml配置文件

头部信息dtd改成最新的

?

1

2

3

4

<?xml version= "1.0" encoding= "utf-8" ?>

<!doctype struts public

  "-//apache software foundation//dtd struts configuration 2.5//en"

  "http://struts.apache.org/dtds/struts-2.5.dtd" >

做以上修改之后

对于struts2.5以上的版本就可以用url+!+方法访问action某个方法

总结

以上就是这篇文章的全部内容了,希望本文的内容对大家的学习或者工作具有一定的参考学习价值,如果有疑问大家可以留言交流,谢谢大家对的支持。

原文链接:https://blog.csdn.net/gh670011677/article/details/75019003

查看更多关于Struts2.5版本struts.xml与web.xml配置的更改方法的详细内容...

  阅读:13次