0

I have a scenario where I need a spring controller in addition to jersey rest APIs in my application. APIs are working fine but when the spring controller responds back the jsp isn't displayed, instead server responds with 404.

1 * Server has received a request on thread http-bio-8080-exec-2
1 > GET http://localhost:8080/springapp/WEB-INF/views/hello.jsp
1 > accept: */*
1 > accept-encoding: gzip, deflate, sdch
1 > accept-language: en-US,en;q=0.8
1 > cache-control: no-cache
1 > connection: keep-alive
1 > content-type: application/json
1 > host: localhost:8080
1 > postman-token: e6d831b9-7897-0890-14a3-d005776f98e8
1 > user-agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Ubuntu Chromium/48.0.2564.116 Chrome/48.0.2564.116 Safari/537.36

14:16:42.739 [http-bio-8080-exec-2] INFO  edu.lalit.config.FeatureRegistration - 1 * Server responded with a response on thread http-bio-8080-exec-2
1 < 404

web.xml

<!-- spring servlet -->
    <servlet>
            <servlet-name>spring-servlet</servlet-name>
            <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>

            <init-param>
                <param-name>contextConfigLocation</param-name>
                <param-value>
                    classpath:application-context.xml               
                </param-value>
            </init-param>
            <load-on-startup>1</load-on-startup>
        </servlet>      
        <servlet-mapping>
            <servlet-name>spring-servlet</servlet-name>
            <url-pattern>/proxy/*</url-pattern>
        </servlet-mapping>

        <!-- jersey Servlet -->
        <servlet>
            <servlet-name>jersey-servlet</servlet-name>
            <servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
            <init-param>
                <param-name>jersey.config.server.provider.packages</param-name>
                <param-value>
                            edu.lalit
                </param-value>
            </init-param>
            <init-param>
                <param-name>javax.ws.rs.Application</param-name>
                <param-value>edu.lalit.config.FeatureRegistration</param-value>
            </init-param>
            <init-param>
                <param-name>jersey.config.beanValidation.enableOutputValidationErrorEntity.server</param-name>
                <param-value>true</param-value>
            </init-param>
            <load-on-startup>2</load-on-startup>
        </servlet>

        <servlet-mapping>
            <servlet-name>jersey-servlet</servlet-name>
            <url-pattern>/*</url-pattern>
        </servlet-mapping>

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

application-context.xml

<beans:bean
    class="org.springframework.web.servlet.view.InternalResourceViewResolver">
    <beans:property name="prefix">
        <beans:value>/WEB-INF/views/</beans:value>
    </beans:property>
    <beans:property name="suffix">
        <beans:value>.jsp</beans:value>
    </beans:property>
</beans:bean>

<mvc:annotation-driven/>

spring controller

@Controller
public class BankResponseController {

    @RequestMapping(method = RequestMethod.GET, path = "spring/test/{first}/{second}")
    public String getData(@PathVariable(value = "first") String first, 
            @PathVariable(value = "second") String second) {
        System.out.println("inside spring controller");
        System.out.println("first: " + first + " second: " + second);
        return "hello";
    }

}

Request URL

http://localhost:8080/springapp/proxy/test/hello/lalit

What should be done to respond back with a jsp ?

Lalit Mehra
  • 1,183
  • 1
  • 13
  • 33
  • Check [this out](http://stackoverflow.com/q/12422660/2587435) – Paul Samsotha Mar 05 '16 at 09:03
  • @peeskillet the link mentions to change the servlet to filter but then my request won't be caught at spring end ... – Lalit Mehra Mar 05 '16 at 10:33
  • Did you also set the required properties to forward the request? – Paul Samsotha Mar 05 '16 at 10:36
  • yes ... that didn't work for me – Lalit Mehra Mar 05 '16 at 10:38
  • You _could_ just change the Jersey url-mapping. Or Jersey also offers MVC support. But for me personally, with this issue, making the change to filter works. I usually the forwardOn404 property though mentioned in the second high ranked answer. The only thing about this though is the performance hit you get because all requests go through Jersey first, then it gets forwarded. I just don't use /* for Jersey anymore if I need to serve static content or have any other servlets in the app – Paul Samsotha Mar 05 '16 at 10:43
  • @peeskillet changed the mappings for jersey and spring, now they are listening different url paths ... thanks man !!! – Lalit Mehra Mar 05 '16 at 11:33

0 Answers0