Spring视图映射问题

时间:2011-01-29 14:10:02

标签: spring jsp spring-mvc

我在Spring Web MVC中遇到了我的View Mapping问题。

分派器-servlet.xml中:

...
<bean class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping" />
<bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter" />
<context:component-scan base-package="de.bigbohne.smartmeter.controller" />

<bean id="viewResolver" class="org.springframework.web.servlet.view.UrlBasedViewResolver">
   <property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/>
   <property name="prefix" value="/WEB-INF/views/"/>
</bean>
...

我的控制器:

@Controller
public class FrontPage {

    @RequestMapping("/index.htm")
    public ModelAndView Index(Model mdl){
       ModelAndView mav =  new ModelAndView("frontPage.jsp");
       return mav;
    }
}

我收到 404错误,说它缺少 / SmartMeter / WEB-INF / views / index

在我的意见中,它必须是: /SmartMeter/WEB-INF/views/frontPage.jsp

我错过了什么? (我正在使用Jetty 7.2和Spring 3.0.5)

修改1:

的web.xml:

<servlet>
 <servlet-name>FrontController</servlet-name>
 <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
 <load-on-startup>1</load-on-startup>
</servlet>

<servlet-mapping>
 <servlet-name>FrontController</servlet-name>
 <url-pattern>*.htm</url-pattern>
</servlet-mapping>

2 个答案:

答案 0 :(得分:1)

尝试更改

<bean id="viewResolver" class="org.springframework.web.servlet.view.UrlBasedViewResolver">

<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver" >

答案 1 :(得分:0)

您需要为视图解析器指定后缀:

<property name="suffix" value=".jsp" />