标签:规则 location 跳转 控制 lan tps map 实体 handler
位于 /WEB-INF/web.xml
<!--1.注册DispatcherServlet-->
<servlet>
<servlet-name>springmvc</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<!--关联一个springmvc的配置文件:【servlet-name】.xml-->
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:springmvc-servlet.xml</param-value>
</init-param>
<!--启动级别-1:和服务器同时启动-->
<load-on-startup>1</load-on-startup>
</servlet>
<!-- 在SpringMVC中: -->
<!-- / 匹配所有的请求,但不匹配.jps文件-->
<!-- /* 匹配所有的请求,并且匹配.jsp文件-->
<servlet-mapping>
<servlet-name>springmvc</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<?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.xsd">
<bean class="org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping"/>
<bean class="org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter"/>
<!--视图解析器:DispatcherServlet给他的ModelAndView-->
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver" id="InternalResourceViewResolver">
<!--前缀-->
<property name="prefix" value="/WEB-INF/jsp/"/>
<!--后缀-->
<property name="suffix" value=".jsp"/>
</bean>
<!--Handler-->
<bean id="/hello" class="com.ssozh.controller.HelloController"/>
</beans>
位于classpath:springmvc-servlet.xml
<bean class="org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping"/>
位于classpath:springmvc-servlet.xml
<bean class="org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter"/>
public class HelloController implements Controller {
@Override
public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception {
//ModelAndView 模型和视图
ModelAndView mv = new ModelAndView();
//封装对象,放在ModelAndView中。Model
mv.addObject("msg","HelloSpringMVC!");//将HellowSpirngMVC字符串传递给msg变量。
//封装要跳转的视图,放在ModelAndView中
mv.setViewName("hello"); //: /WEB-INF/jsp/hello.jsp
return mv;
}
}
位于classpath:springmvc-servlet.xml
<!--视图解析器:DispatcherServlet给他的ModelAndView-->
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver" id="InternalResourceViewResolver">
<!--前缀-->
<property name="prefix" value="/WEB-INF/jsp/"/>
<!--后缀-->
<property name="suffix" value=".jsp"/>
</bean>
springmvc-servlet.xml
中配置的bean/WEB=INF/jsp/hello.jsp
标签:规则 location 跳转 控制 lan tps map 实体 handler
原文地址:https://www.cnblogs.com/SsoZhNO-1/p/12424947.html