0

I can't seem to find any sort of information on how to configure both Jersey and Struts 2 in one app. I have the following web.xml:

   <servlet>
                <servlet-name>ServletAdaptor</servlet-name>
                <servlet-class>
                    com.sun.jersey.spi.container.servlet.ServletContainer
                </servlet-class>
                <load-on-startup>1</load-on-startup>
            </servlet>
            <servlet-mapping>
                <servlet-name>ServletAdaptor</servlet-name>
                <url-pattern>/ajax/*</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>

I am using Struts 2 annotation configuration for action classes, results, etc. However, I still have a struts.xml in the src/ that gets put into the WEB-INF/classes to configure a few things. One of them is an option not easily found on google about telling Struts to ignore one or more URL patterns. So given that I want ALL requests EXCEPT any url with ajax/* in it, to Struts 2, I have the above and added the ajax/* pattern to the struts.xml like so:

<struts>
    <constant name="struts.devMode" value="true" />
    <constant name="struts.convention.classes.reload" value="true" />
    <constant name="struts.enable.SlashesInActionNames" value="true" />
    <constant name="struts.action.excludePattern" value="/ajax/*?" />

    <package name="default" extends="struts-default" namespace="/">
        <action name="index">
            <result>/index.jsp</result>
        </action>
    </package>
</struts>

As you see, the excludePattern is used to tell Struts what to ignore. Still, I can't get any of my Jersey requests to get through to the resources. They are loading..I see them being round in the log output. The only error I get is that Struts has no action mapped to /ajax/somePath.

So if anyone has configured Struts2 and Jersey, I'd be much appreciated in helping me resolve how to make them work together so that one (or a few url paths) make it through to Jersey, the rest go to Struts2.

Aleksandr M
  • 24,264
  • 12
  • 69
  • 143
user3386877
  • 515
  • 1
  • 5
  • 12
  • possible duplicate of [Jersey with Struts2](http://stackoverflow.com/questions/17293115/jersey-with-struts2) – Aleksandr M May 29 '14 at 08:26
  • If I set below code for struts filter url-pattern ** struts2 /struts/* ** then it rest web service working. But I want to use web service with below code for struts filter url-pattern ** struts2 /struts/* ** – user3386877 Jun 02 '14 at 13:51
  • What is the difference? Have you read linked question and answer? – Aleksandr M Jun 02 '14 at 17:26

0 Answers0