如何用springMVC 返回一个指定的HTML页面
1个回答
2016-08-09 · 百度知道合伙人官方认证企业
育知同创教育
1【专注:Python+人工智能|Java大数据|HTML5培训】 2【免费提供名师直播课堂、公开课及视频教程】 3【地址:北京市昌平区三旗百汇物美大卖场2层,微信公众号:yuzhitc】
向TA提问
关注
展开全部
用springMVC 返回一个指定的HTML页面的方枯滚法:
1、servlet容数纯器调用DispatcherServlet获取请求
2、DispatcherServlet得到controller对应的路径映射并且制定返回HelloWorld,映射到页面 /WEB-INF/view/HelloWorld.html 视图。
3、响应成功后通过 RequestDispatcher.forward("/WEB-INF/views/HelloWorld.html")跳转到指定的html页面
@RequestMapping(value="html", method = RequestMethod.GET )
public String home(Locale locale, Model model) {
return "HelloWorld";
}
配置文件servlet-context.xml:
<!-- Enables the Spring MVC @Controller programming model -->
<annotation-driven />
<!-- Handles HTTP GET requests for /resources/** by efficiently serving up static resources in the ${webappRoot}/resources directory -->
<resources mapping="/resources/**" location="/resources/" />
<!-- Resolves views selected for rendering by @Controllers to .jsp resources in the /WEB-INF/views directory -->
<beans:bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<beans:property name="prefix" value="/WEB-INF/views/" />没毕余
<beans:property name="suffix" value=".html" />
</beans:bean>
1、servlet容数纯器调用DispatcherServlet获取请求
2、DispatcherServlet得到controller对应的路径映射并且制定返回HelloWorld,映射到页面 /WEB-INF/view/HelloWorld.html 视图。
3、响应成功后通过 RequestDispatcher.forward("/WEB-INF/views/HelloWorld.html")跳转到指定的html页面
@RequestMapping(value="html", method = RequestMethod.GET )
public String home(Locale locale, Model model) {
return "HelloWorld";
}
配置文件servlet-context.xml:
<!-- Enables the Spring MVC @Controller programming model -->
<annotation-driven />
<!-- Handles HTTP GET requests for /resources/** by efficiently serving up static resources in the ${webappRoot}/resources directory -->
<resources mapping="/resources/**" location="/resources/" />
<!-- Resolves views selected for rendering by @Controllers to .jsp resources in the /WEB-INF/views directory -->
<beans:bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<beans:property name="prefix" value="/WEB-INF/views/" />没毕余
<beans:property name="suffix" value=".html" />
</beans:bean>
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询