标签:
<servlet>
<servlet-name>springmvc</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:mvc.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>springmvc</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
classpath:
即src的路径 <?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.3.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.3.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.3.xsd">
</beans>
<!-- 配置渲染器 -->
<bean id="jspViewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="viewClass" value="org.springframework.web.servlet.view.InternalResourceView"/>
<!-- 结果视图的前缀 -->
<property name="prefix" value="/WEB-INF/jsp"/>
<!-- 结果视图的后缀 -->
<property name="suffix" value=".jsp"/>
</bean>
<!-- 配置扫描器需要扫描的包 -->
<context:component-scan base-package="com.wen.controller"/>
@Controller
@RequestMapping
public class HelloController {
@RequestMapping("/hello")
public ModelAndView hello(HttpServletRequest request, HttpServletResponse response){
ModelAndView mav = new ModelAndView();
//视图名称
mav.setViewName("hello");
//封装要显示到视图中的数据
mav.addObject("hello", "hello");
return mav;
}
}
hello.jsp代码如下:
<body>
获得的数据为:${hello }
</body>
标签:
原文地址:http://blog.csdn.net/zwx2445205419/article/details/52529661