I am just starting with Spring MVC, trying to create a new project, and ran into a problem for which a guide or tutorial does not help ...
I created a simple application without logic, just trying to configure Spring correctly. The controller simply returns the name of the displayed view, but the view resolver does not pass jsp and returns a 404 error ....
Any help is greatly appreciated.
My web.xml:
<web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<servlet>
<servlet-name>openstats</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>openstats</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
<display-name>OpenStats API Server</display-name>
</web-app>
My openstats-servlet.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
<context:component-scan base-package="org.openstats.api.controller"/>
<bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter"/>
<bean class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping"/>
<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="viewClass"><value>org.springframework.web.servlet.view.JstlView</value></property>
<property name="prefix"><value>/jsp/</value></property>
<property name="suffix"><value>.jsp</value></property>
</bean>
</beans>
The controller itself has no logic, just:
@Controller
public class ProductController {
@RequestMapping(value = "/products.do", method = RequestMethod.GET)
public ModelAndView listProducts(HttpServletRequest request) {
ModelAndView model = new ModelAndView("index");
return model;
}
}
The controller is reached, the problem is trying to render ...
I install log4j in debug and this is part of what I get:
02: 08: 19,702 DEBUG DispatcherServlet: 1094 - Test adapter adapter [Org.springfram ework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter @397b6074] 02: 08: 19,803 DEBUG HandlerMethodInvoker: 134 - : public org.springframework.web.servlet.ModelAndView org.openstats.api.controller.ProductController.listProducts(javax.servlet.http.HttpServletRequest) 02: 08: 19,833 DEBUG DefaultListableBeanFactory: 1367 - afterPropertiesSet() bean 'index' 02: 08: 19,876 DEBUG InternalResourceViewResolver: 81 - Cached view [index] 02: 08: 19 877 DEBUG DispatcherServlet: 1181 - [Org.springframework.web.servlet.view.JstlView: name 'index'; URL [/jsp/index.jsp]] 'openstats' 02: 08: 19 877 DEBUG JstlView: 240 - name 'index' {} {} 02: 08: 19,923 DEBUG JstlView: 234 - [/jsp/index.jsp] InternalResourceView 'index' 02: 08: 19,926 DEBUG DispatcherServlet: 955 - 'openstats' Last-Modified [/api-server/jsp/index.jsp] 02: 08: 19,927 DEBUG DispatcherServlet: 1054 - [Org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping@440c4cee] DispatcherServlet 'openstats' 02: 08: 19,928 DEBUG DefaultAnnotationHandlerMapping: 179 - [/jsp/index.jsp] 02: 08: 19,929 DEBUG DispatcherServlet: 962 - getLastModified 02: 08: 19,937 DEBUG DispatcherServlet: 781 - openstats [/api-server/jsp/index.jsp] 02: 08: 19,938 DEBUG DispatcherServlet: 843 - : GET /api -server/products.do HTTP/1.1
jsp "webapp" index.jsp.
.