最近了解了下struts2,关于web.xml的配置有一个一问: 
    <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>

在配置“filter-mapping”的url-pattern中都为/*,我现在又加入了一个快速开发的组件,该组件在web.xml中有配置信息:
<servlet>
<servlet-name>djfocus-action</servlet-name>
<servlet-class>com.djfocus.ActionServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>djfocus-action</servlet-name>
<url-pattern>/djfocus/servAction</url-pattern>
</servlet-mapping>
 
结果启动tomcat运行后,在web页面用到了组件的网页就会报错,报错内容如下:
Could not find action or result
There is no Action mapped for action name servAction. - [unknown location] 
估计是struts2的配置在解析的时候把servlet-mapping中的url抓取出来了。本人没有深入去研究struts2,想请教下大家,可以解决这个问题嘛,遇到了url-pattern问题?

解决方案 »

  1.   

    <filter-mapping>
    <filter-name>struts2</filter-name>
    <url-pattern>/*.jsp</url-pattern>
    </filter-mapping>
    <filter-mapping>
    <filter-name>struts2</filter-name>
    <url-pattern>/*.action</url-pattern>
    </filter-mapping>
    可以改成这个样子试试
      

  2.   

    肯定会报错啦,你的struts把所有的请求给拦截了!改成楼上的/*.action吧!或者在把这个请求写成一个action呀!干吗用了struts还写自己的servlet类呢 ?
      

  3.   

    Invalid <url-pattern> /*.action in filter mapping
    还是不行呢,改成/*.action??
      

  4.   

    <?xml version="1.0" encoding="UTF-8"?>
    <web-app 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">
    <welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
    </welcome-file-list> <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>*.action</url-pattern>
    </filter-mapping>
    <filter-mapping>
    <filter-name>struts2</filter-name>
    <url-pattern>*.jsp</url-pattern>
    </filter-mapping>
    <context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>classpath:application-*.xml</param-value>
    </context-param>
    <listener>
    <listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
    </listener>
    <listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener> <filter>
    <filter-name>encoding</filter-name>
    <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
    <init-param>
    <param-name>encoding</param-name>
    <param-value>UTF-8</param-value>
    </init-param>
    </filter>
    <filter-mapping>
    <filter-name>encoding</filter-name>
    <url-pattern>/*</url-pattern>
    </filter-mapping>
    <servlet>
    <servlet-name>Connector</servlet-name>
    <servlet-class>net.fckeditor.connector.ConnectorServlet</servlet-class> <load-on-startup>1</load-on-startup> </servlet>
    <servlet-mapping>
    <servlet-name>Connector</servlet-name>
    <url-pattern>                                
            /fckeditor/editor/filemanager/connectors/* 
          </url-pattern>
          </servlet-mapping>
    </web-app>
      

  5.   

    曾经的配置,如果还是不行建议直接更改struts的配置 让他拦截*.do
      

  6.   

    <url-pattern>/djfocus/servAction/*</url-pattern>
    servAction命名控件或是目录下的所有请求,具体要看请求地址
    也就是地址中有servAction的
      

  7.   

    <filter-mapping>
    <filter-name>struts2</filter-name>
            <url-pattern>*.jspa</url-pattern>
        </filter-mapping>