2

Why my filtering does not work for me and how to setup it to work?

There is my web.xml:

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<servlet>
    <display-name>GameServlet</display-name>
    <servlet-name>GameServlet</servlet-name>
    <servlet-class>ajaxdemo.action.GameServlet</servlet-class>
    <load-on-startup>0</load-on-startup>
</servlet>
<servlet-mapping>
    <servlet-name>GameServlet</servlet-name>
    <url-pattern>/gameservlet</url-pattern>
</servlet-mapping>
<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>

<welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>

On this configuration GameServlet does not receive anything and web server reports that there are no action mapping for /gameservlet URL.

If I comment filter-mapping this servlet works fine by this URL.

How to get working Struts filters and servlet filter simultaneously, the point is servlet should work only with /gameservlet URL, all others should be processed by Struts. I cannot understand how to create URL patterns for my case.

Roman C
  • 49,761
  • 33
  • 66
  • 176
Atark
  • 23
  • 1
  • 5
  • possible duplicate of [How to use Servlet in Struts2](http://stackoverflow.com/questions/5295491/how-to-use-servlet-in-struts2) – Andrea Ligios Mar 16 '15 at 22:34
  • from first view duplication, don't know to accept it or not, the point is I knew that Servlet and Struts can work together, it is why I didn't find that you specified, my question is more precise to problem, for me question was exactly concerned to patterns. – Atark Mar 16 '15 at 22:49
  • Possible duplicate of [Jersey with Struts2](https://stackoverflow.com/questions/17293115/jersey-with-struts2) – Aleksandr M Oct 31 '17 at 20:57

1 Answers1

2

You should add excludePattern constant to struts.xml to exclude servlet mapping URL from Struts processing.

<struts>
    <constant name="struts.action.excludePattern" value="/gameservlet/?.*"/>
    ...
</struts> 
Roman C
  • 49,761
  • 33
  • 66
  • 176
  • 1
    It works, thank you very much, I have seen tons of tutorials for Struts and servlets and could not find this very simple thing. – Atark Mar 16 '15 at 21:43