前言
升級之后的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