知识大全 修改Struts2的struts.xml配置文件位置

Posted 位置

篇首语:白日放歌须纵酒,青春作伴好还乡。本文由小常识网(cha138.com)小编为大家整理,主要介绍了知识大全 修改Struts2的struts.xml配置文件位置相关的知识,希望对你有一定的参考价值。

修改Struts2的struts.xml配置文件位置  以下文字资料是由(全榜网网www.cha138.com)小编为大家搜集整理后发布的内容,让我们赶快一起来看一下吧!

  默认情况下 Struts 的配置文件名称为struts xml 且该文件放在src根目录下 如下图所示

>

  如果需要修改struts xml的位置 例如把struts xml放到struts 文件夹下 结构如下图所示 该怎么办呢?

>

  Struts 在web xml中的一般配置如下

  []

  struts

   apache struts dispatcher ng filter StrutsPrepareAndExecuteFilter

  struts

  /*

  struts

   apache struts dispatcher ng filter StrutsPrepareAndExecuteFilter

  struts

  /*

  为了弄清Stuts 是如何加载配置文件的 先查看Struts 的StrutsPrepareAndExecuteFilter类

  [java] package apache struts dispatcher ng filter;

  /**

  * Handles both the preparation and execution phases of the Struts dispatching process This filter is better to use

  * when you don t have another filter that needs access to action context information such as Sitemesh

  */

  public class StrutsPrepareAndExecuteFilter implements StrutsStatics Filter

  protected PrepareOperations prepare;

  protected ExecuteOperations execute;

  protected List excludedPatterns = null;

  public void init(FilterConfig filterConfig) throws ServletException

  InitOperations init = new InitOperations();

  try

  FilterHostConfig config = new FilterHostConfig(filterConfig);

  init initLogging(config);

  Dispatcher dispatcher = init initDispatcher(config);

  init initStaticContentLoader(config dispatcher);

  prepare = new PrepareOperations(filterConfig getServletContext() dispatcher);

  execute = new ExecuteOperations(filterConfig getServletContext() dispatcher);

  this excludedPatterns = init buildExcludedPatternsList(dispatcher);

  postInit(dispatcher filterConfig);

   finally

  init cleanup();

  

  

  /**

  * Callback for post initialization

  */

  protected void postInit(Dispatcher dispatcher FilterConfig filterConfig)

  

  public void doFilter(ServletRequest req ServletResponse res FilterChain chain) throws IOException ServletException

  HttpServletRequest request = (HttpServletRequest) req;

  HttpServletResponse response = (HttpServletResponse) res;

  try

  prepare setEncodingAndLocale(request response);

  prepare createActionContext(request response);

  prepare assignDispatcherToThread();

  if ( excludedPatterns != null && prepare isUrlExcluded(request excludedPatterns))

  chain doFilter(request response);

   else

  request = prepare wrapRequest(request);

  ActionMapping mapping = prepare findActionMapping(request response true);

  if (mapping == null)

  boolean handled = execute executeStaticResourceRequest(request response);

  if (!handled)

  chain doFilter(request response);

  

   else

  execute executeAction(request response mapping);

  

  

   finally

  prepare cleanupRequest(request);

  

  

  public void destroy()

  prepare cleanupDispatcher();

  

  

  package apache struts dispatcher ng filter;

  /**

  * Handles both the preparation and execution phases of the Struts dispatching process This filter is better to use

  * when you don t have another filter that needs access to action context information such as Sitemesh

  */

  public class StrutsPrepareAndExecuteFilter implements StrutsStatics Filter

  protected PrepareOperations prepare;

  protected ExecuteOperations execute;

  protected List excludedPatterns = null;

  public void init(FilterConfig filterConfig) throws ServletException

  InitOperations init = new InitOperations();

  try

  FilterHostConfig config = new FilterHostConfig(filterConfig);

  init initLogging(config);

  Dispatcher dispatcher = init initDispatcher(config);

  init initStaticContentLoader(config dispatcher);

  prepare = new PrepareOperations(filterConfig getServletContext() dispatcher);

  execute = new ExecuteOperations(filterConfig getServletContext() dispatcher);

  this excludedPatterns = init buildExcludedPatternsList(dispatcher);

  postInit(dispatcher filterConfig);

   finally

  init cleanup();

  

  

  /**

  * Callback for post initialization

  */

  protected void postInit(Dispatcher dispatcher FilterConfig filterConfig)

  

  public void doFilter(ServletRequest req ServletResponse res FilterChain chain) throws IOException ServletException

  HttpServletRequest request = (HttpServletRequest) req;

  HttpServletResponse response = (HttpServletResponse) res;

  try

  prepare setEncodingAndLocale(request response);

  prepare createActionContext(request response);

  prepare assignDispatcherToThread();

  if ( excludedPatterns != null && prepare isUrlExcluded(request excludedPatterns))

  chain doFilter(request response);

   else

  request = prepare wrapRequest(request);

  ActionMapping mapping = prepare findActionMapping(request response true);

  if (mapping == null)

  boolean handled = execute executeStaticResourceRequest(request response);

  if (!handled)

  chain doFilter(request response);

  

   else

  execute executeAction(request response mapping);

  

  

   finally

  prepare cleanupRequest(request);

  

  

  public void destroy()

  prepare cleanupDispatcher();

  

  可以看到 有个public void init(FilterConfig filterConfig) throws ServletException 方法 很明显 这个方法在启动时会被调用 然后加载classes目录下的struts xml配置文件 配置文件参数名称为filterConfig 因此 我们可以指定Struts Filter 的参数 这和指定Servlet参数相同 配置即可 配置如下

  []

  struts

   apache struts dispatcher ng filter StrutsPrepareAndExecuteFilter

  filterConfig

  classpath:struts /struts xml

  struts

  /*

  struts

   apache struts dispatcher ng filter StrutsPrepareAndExecuteFilter

  filterConfig

  classpath:struts /struts xml

  struts

  /*

cha138/Article/program/Java/ky/201311/28733

相关参考

知识大全 struts.xml常用配置解析

Struts2教程3:struts.xml常用配置解析  以下文字资料是由(全榜网网www.cha138.com)小编为大家搜集整理后发布的内容,让我们赶快一起来看一下吧

知识大全 Struts2配置文件的配置

Struts2配置文件的配置  以下文字资料是由(全榜网网www.cha138.com)小编为大家搜集整理后发布的内容,让我们赶快一起来看一下吧!  配置webxml文件

知识大全 Struts2的properties配置文件详解

Struts2的properties配置文件详解  以下文字资料是由(全榜网网www.cha138.com)小编为大家搜集整理后发布的内容,让我们赶快一起来看一下吧!##

知识大全 动态修改WCF客户端配置文件终结点的地址的几种方法

动态修改WCF客户端配置文件终结点的地址的几种方法  以下文字资料是由(全榜网网www.cha138.com)小编为大家搜集整理后发布的内容,让我们赶快一起来看一下吧! 

知识大全 spring struts2 ibatis框架整合开发

这里主要介绍一下spring+struts+ibatis所需要的jar包文件spring所需包  以上包为spring配置基本包ibatis所需包  有解决方法的朋友们希望能回复  与struts整合

知识大全 修改struts2的.action后缀名

  晕了整了一个晚上就是无法访问原来是因为用了do的后缀名改成action的后缀名就可以访问了而且只能用XXXaction的形式否则无法访问  看来还是由于对struts的过滤机制不是很清楚  但是我

知识大全 Struts2基于注解的Action配置

Struts2基于注解的Action配置  以下文字资料是由(全榜网网www.cha138.com)小编为大家搜集整理后发布的内容,让我们赶快一起来看一下吧!  使用注解

知识大全 Struts2初始配置的几点注意

Struts2初始配置的几点注意  以下文字资料是由(全榜网网www.cha138.com)小编为大家搜集整理后发布的内容,让我们赶快一起来看一下吧!  按照教程上的方法

知识大全 struts2整合tiles及配置

  一基本包(个)  monsloggingjar  monsfileuploadjar  ognljar  strutscorejar  xworkjar  freemarkerjar  二整合ti

知识大全 struts2实现文件下载

  使用Struts控制文件下载可能很多人会觉得文件下载太简单直接在页面上给出一个超级链接该链接的href属性等于要下载文件的文件名不就可以实现文件下载了吗?大部分时候的确可以实现文件下载但如果该文件