struts2web.xmlservlet-filtersurl-patternaction-mapping

Filter mapping Url pattern *.action not working struts2


in the struts2 web.xml application i have filter and servlet

web.xml

...
<servlet>
        <servlet-name>SchServlet</servlet-name>
        <servlet-class>com.vk.translate.report.SchServlet</servlet-class>
    </servlet>
    <servlet-mapping>
        <servlet-name>SchServlet</servlet-name>
        <url-pattern>/SchServlet</url-pattern>
    </servlet-mapping>
...

<filter>
        <filter-name>struts</filter-name> 
        <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
        <!-- <init-param> <param-name>actionPackages</param-name> <param-value>com.mycompany.myapp.actions</param-v2alue> 
            </init-param> -->
    </filter>
    <filter-mapping>
        <filter-name>struts</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>

...

while invoking the servlet it maps that request as action since the Filer Url pattern as

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

i try to modify that as

 <url-pattern>/*.action</url-pattern>

It showing error.Can u please help how can i call the servlet.

<url-pattern>/SchServlet</url-pattern>

in this case while invoking the servlet it shows as

There is no Action mapped for namespace [/] and action name [SchServlet] associated with context path [/TranslateApp].


Solution

  • This one worked

    in struts.xml

    <constant name="struts.action.excludePattern" value="/SchServlet"></constant>
    

    in web.xml

    <filter>
            <filter-name>struts</filter-name> 
            <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
    
        </filter>
        <filter-mapping>
            <filter-name>struts</filter-name>
            <url-pattern>*.action</url-pattern>
        </filter-mapping>
    
        <servlet>
            <servlet-name>SchServlet</servlet-name>
            <servlet-class>com.vk.translate.report.SchServlet</servlet-class>
        </servlet>
        <servlet-mapping>
            <servlet-name>SchServlet</servlet-name>
            <url-pattern>/SchServlet</url-pattern>
        </servlet-mapping>
    

    reference: Struts2 exclude pattern not working