Spring视图映射问题
我的 Spring Web MVC 中的视图映射有问题。
Dispatcher-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
在我看来,它必须是:< em>/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>
I've got a problem with my View Mapping in the Spring Web MVC.
Dispatcher-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>
...
My Controller:
@Controller
public class FrontPage {
@RequestMapping("/index.htm")
public ModelAndView Index(Model mdl){
ModelAndView mav = new ModelAndView("frontPage.jsp");
return mav;
}
}
I get an 404 Error saying that it's missing /SmartMeter/WEB-INF/views/index
In my oppinion it must be: /SmartMeter/WEB-INF/views/frontPage.jsp
What am I missing? (I'm using Jetty 7.2 and Spring 3.0.5)
Edit 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>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试更改
为
Try to change
to
您需要为视图解析器指定后缀:
You need to specify a suffix to the view resolver: