Java – spring MVC – JSP cannot be rendered
I just started trying to create a new project using spring MVC, and I encountered a problem. There is no manual or tutorial that seems to help
I've set up a simple application without logic, just trying to configure spring correctly The controller only returns the name of the view to be displayed, but the view parser does not render the JSP and returns 404 error
Any help is greatly appreciated
My web XML is:
<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"/> <!-- Enable to request mappings PER METHOD --> <bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter"/> <!-- Enable annotated POJO @Controller --> <bean class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping"/> <!-- Define the view resolver to use jsp files within the jsp folder --> <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, it just:
@Controller public class ProductController { @RequestMapping(value = "/products.do",method = RequestMethod.GET) public ModelAndView listProducts(HttpServletRequest request) { ModelAndView model = new ModelAndView("index"); return model; } }
Reaching the controller, the problem is when trying to render
I set log4j during debugging, which is part of what I got:
My JSP folder is in "webapp" and index JSP file exists
Thank you in advance
Solution
I'm interested in spring 3 X has the same problem
Editor: I figured it out myself: -) I used the following servletmapping:
<servlet-mapping> <servlet-name>spring-frontcontroller</servlet-name> <url-pattern>/*</url-pattern> </servlet-mapping>
Edit the URL pattern to, for example * Do fixed the problem of not rendering JSPS But this leaves the question of how your URL pattern is implemented