1. struts2工程配置web.xml
具體的過濾器類變了,2.0是這樣配置
<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>
2.1以後是這樣配置
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
2. struts-2.3.1.2 web.xml中應該怎麼配置
具體的過濾器類變了,2.0是這樣配置 struts2 org.apache.struts2.dispatcher.FilterDispatcher struts2 /* 2.1以後是這樣配置 struts2 org.apache.struts2.dispatcher.ng.filter.StrutsPrepareFilter struts2 /*
3. 如何在web.xml中設置struts.xml
為什麼把struts2的配置文件,引入web.xml呢
<!--定義Struts2的FilterDispatcher的Filter-->
<filter>
<!--定義核心Filter的名字-->
<filter-name>struts2</filter-name>
<!--定義核心Filter的實現類-->
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>
<!--FilterDispatcher用來初始化Struts2並且處理所有的Web請求-->
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>*.do</url-pattern>
</filter-mapping>
這樣寫不就行了嗎?
4. struts2的web.xml有哪些配置
<!--配置過濾器,如下設置是struts2的主要攔截器 -->
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
</filter>
<!-- 對應於<filter>配置的<filter-mapping>,一個filter可以對應配置多個<filter-mapping> -->
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>*.action</url-pattern>
</filter-mapping>
注意:<filter-mapping>中的<filter-name>必須跟<filter>中的<filter-name>相同。
這些個東西是在你發出請求的時候就執行的,比如你配置的那個/*是指無論你發出什麼請求都要走struts2的攔截器,通過攔截器來查找你請求的東西,並作出響應;我後來配置的那個*.action是當你發出action請求時也得經過struts2的攔截器,你也可以只寫
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
5. Struts2的web.xml配置問題
配置成*.do或者*.action要在訪問的url加上對應的.do或者.action
6. struts2修改struts.xml路徑,web.xml中怎麼配置才能用
如果你的struts.xml路徑為:
WebRoot/config/struts/struts.xml
可以這樣寫
<param-value>
struts-default.xml,
struts-plugin.xml,
../config/struts/struts2.xml
</param-value>
如果不對請把struts.xml路徑改為:WebRoot/web-inf/config/struts/struts.xml
提供另一種方法
假設你的工程下有 admin 和common兩個包
common為公共包,包下存放structs.xml 你需要寫
<struts>
<package name="common" extends="struts-default">
<include file="struts-admin.xml" />
</struts>
admin 為管理員包,包下存放struts-admin.xml你需要寫
<struts>
<package name="admin" extends="common">
</struts>
7. struts2中web.xml的配置
/* ------->所有的請求 不管你後綴名是什麼 都會攔截到 比如:http://localhost:8080/xxx/index.jsp
*.action ------->請求是以ation 結尾的 會被攔截到 比如:http://localhost:8080/xxx/index.action
8. struts2的web.xml文件配置問題
因為你還沒加struts2.xml,配置文件
伺服器啟動的時候肯定報錯了,你看了沒有、。
9. struts為什麼要配置web.xml
因為web項目的啟動文件就是web.xml,所以到入struts框架的過濾器需要在此文件配置
10. struts2的web.xml怎麼配置
任何MVC框架都需要與Web應用整合,這就不得不藉助於web.xml文件,只有配置在web.xml文件中Servlet才會被應用載入。
通常,所有的MVC框架都需要Web應用載入一個核心控制器,對於Struts2框架而言,需要載入FilterDispatcher,只要Web應用負責載入FilterDispatcher,FilterDispatcher將會載入Struts2框架。
因為Struts2將核心控制器設計成Filter,而不是一個普通Servlet。故為了讓Web應用載入FilterDispatcher,只需要在web.xml文件中配置FilterDispatcher即可。
標准配置文件如下:
<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_9" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<display-name>Struts Blank</display-name>
<filter>
<!-- 配置Struts2核心Filter的名字 -->
<filter-name>struts2</filter-name>
<!-- 配置Struts2核心Filter的實現類 -->
<filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
<init-param>
<!-- 配置Struts2框架默認載入的Action包結構,可以沒有。 -->
<param-name>actionPackages</param-name>
<param-value>org.apache.struts2.showcase.person</param-value>
</init-param>
<!-- 配置Struts2框架的配置提供者類 -->
<init-param>
<param-name>configProviders</param-name>
<param-value>lee.MyConfigurationProvider</param-value>
</init-param>
</filter>
<!-- 配置Filter攔截的URL -->
<filter-mapping>
<!-- 配置Struts2的核心FilterDispatcher攔截所有用戶請求 -->
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
</web-app>
*如上,當配置Struts2的FilterDispatcher類時,可以指定一系列的初始化參數,為該Filter配置初始化參數時,其中有3個初始化參數有特殊意義:
config:使用逗號隔開的字元串,每個字元串都是一個XML配置文件的位置。Struts框架將自動載入該屬性指定的系列配置文件。
actionPackages:使用逗號隔開的字元串,每個字元串都是一個包空間,Struts2框架將掃描這些包空間下的Action。
configProviders:配置自己的ConfigurationProvider類。
還可以在此處配置Struts2常量,每個<init-param>元素配置一個Struts2常量,其中<param-name>子元素指定了常量name,而<param-value>子元素指定了常量value。
*在web.xml中配置了<Filter>元素,還需要配置該Filter攔截的URL。通常,我們讓該Filter攔截所有的用戶請求。可以能過<filter-mapping>元素配置。