简体   繁体   中英

Spring, Jersey and Viewable JSP Integration

I'm trying to integrate Spring 3.0.5 with Jersey 1.4. I seem to have everything working, but whenever I try and return a Viewable that points to a JSP, I get a 404 error. When I wasn't using spring I could use this filter:

<filter>
    <filter-name>Jersey Filter</filter-name>
    <filter-class>com.sun.jersey.spi.container.servlet.ServletContainer</filter-class>
    <init-param>
        <param-name>com.sun.jersey.config.feature.Redirect</param-name>
        <param-value>true</param-value>
    </init-param>
    <init-param>
        <param-name>com.sun.jersey.config.property.packages</param-name>
        <param-value>cheetah.frontend.controllers</param-value>
    </init-param>
    <init-param>
        <param-name>com.sun.jersey.config.feature.FilterForwardOn404</param-name>
        <param-value>true</param-value>
    </init-param>
    <init-param>
        <param-name>com.sun.jersey.config.property.WebPageContentRegex</param-name>
        <param-value>/(images|css|jsp)/.*</param-value>
    </init-param>
</filter>

And I could return a Viewable to any JSP's, image, css that were stored in the appropriate folder. However, now that I have to use the SpringServlet to get spring integration, I'm at a loss for how to access resources, since I can't use the filter above. I've tried using this servlet mapping with no luck:

<servlet>  
    <servlet-name>jerseyspring</servlet-name> 
    <servlet-class>com.sun.jersey.spi.spring.container.servlet.SpringServlet</servlet-class>  
    <load-on-startup>1</load-on-startup>
    <init-param>
        <param-name>com.sun.jersey.config.property.WebPageContentRegex</param-name>
        <param-value>/(images|css|jsp)/.*</param-value>
    </init-param>
</servlet>  
<servlet-mapping>  
    <servlet-name>jerseyspring</servlet-name>  
    <url-pattern>/*</url-pattern>  
</servlet-mapping>

Does anyone know the proper configurations to achieve this?

Thanks for any help.

I discovered that you can use the SpringServlet as a filter:

<filter>
    <filter-name>Jersey Filter</filter-name>
    <filter-class>com.sun.jersey.spi.spring.container.servlet.SpringServlet</filter-class>
    <init-param>
        <param-name>com.sun.jersey.config.feature.Redirect</param-name>
        <param-value>true</param-value>
    </init-param>
    <init-param>
        <param-name>com.sun.jersey.config.feature.FilterForwardOn404</param-name>
        <param-value>true</param-value>
    </init-param>
    <init-param>
        <param-name>com.sun.jersey.config.property.WebPageContentRegex</param-name>
        <param-value>/(images|css|jsp)/.*</param-value>
    </init-param>
</filter>

<filter-mapping>
    <filter-name>Jersey Filter</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>

Which really should have been obvious to me since I used a Servlet in my original filter!

This seems similar to the default Servlet handler recently added to Spring.

I suspect your Viewable resource is being processed by the jerseyspring Servlet rather than a static content handling Servlet (the "default" Servlet discussed in the above link).

What happens if you change your configuration to use <url-pattern>/</url-pattern> ?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM