0

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].

Roman C
  • 49,761
  • 33
  • 66
  • 176
Vinoth Kumar
  • 111
  • 1
  • 4
  • 8

2 Answers2

2

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

Community
  • 1
  • 1
Vinoth Kumar
  • 111
  • 1
  • 4
  • 8
0

Use:

<url-pattern>*.action</url-pattern>
Kevin Bowersox
  • 93,289
  • 19
  • 159
  • 189
  • got this error "Servlet failed with Exception The Struts dispatcher cannot be found. This is usually caused by using Struts tags without the associated filter. Struts tags are only usable when the request has passed through its servlet filter, which initializes the Struts dispatcher needed for this tag. - [unknown location]" – Vinoth Kumar Mar 17 '14 at 09:14
  • Did you hit a url like: `http://domain.com/something.action`? The url you hit must match the pattern in order for the struts servlet to be invoked. – Kevin Bowersox Mar 17 '14 at 09:17
  • No i cant able to login the application i got this error in the welcome page itself `http://domain.com/welcome` – Vinoth Kumar Mar 17 '14 at 09:23