If you want to serve static content from the same WAR as Jersey resources, it is possible to configure Jersey to run as a filter rather than a Servlet.
You can then define the property com.sun.jersey.config.property.WebPageContentRegex
to exclude URLs matching the regular expression from being handled by Jersey. Instead request matching the pattern will fall through to the next filter and eventually the default Servlet, which can respond with your static content in the normal way.
<filter> <filter-name>jerseyFilter</filter-name> <filter-class>com.sun.jersey.spi.spring.container.servlet.SpringServlet</filter-class> <init-param> <param-name>com.sun.jersey.config.property.WebPageContentRegex</param-name> <param-value>/static/.*</param-value> </init-param> </filter> <filter-mapping> <filter-name>jerseyFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> |
Thank you, very helpful and much easier than writing complex things like an default servlet…
Jersey 2.0 apparently changes the property name to “jersey.config.servlet.filter.staticContentRegex”
how to do the same configuration without web.xml. can you please share the java snippet for the same. It would be really helpful