二.初次使用SpringMVC
2021-03-29 18:26
标签:classpath exception att org ret version 视图 work dispatch 别忘了,对于MVC中的所有bean,我们都要将其放到Spring的IOC容器当中去。 2.SpringMVC的作用
3.简单使用 首先配置web.xml 接着配置spring-mvc.xml 接着开始测试,使用最简单,最纯朴的原生方式,继承Controller层的接口 实现对应的方法。 idea显示,说明配置了嗷。 我们之前配置了视图解析器的前缀了后缀,所以 setViewName("")---》就会拼接添加前缀 /WEB-INF/jsp/和 后缀.jsp 二.初次使用SpringMVC 标签:classpath exception att org ret version 视图 work dispatch 原文地址:https://www.cnblogs.com/whydbk/p/13599390.html1.Spring大杂烩
xml version="1.0" encoding="UTF-8"?>
web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"
version="4.0">
servlet>
servlet-name>spring-mvcservlet-name>
servlet-class>org.springframework.web.servlet.DispatcherServletservlet-class>
init-param>
param-name>contextConfigLocationparam-name>
param-value>classpath:spring-mvc.xmlparam-value>
init-param>
load-on-startup>1load-on-startup>
servlet>
servlet-mapping>
servlet-name>spring-mvcservlet-name>
url-pattern>/url-pattern>
servlet-mapping>
web-app>
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"/>
bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
property name="prefix" value="/WEB-INF/jsp/"/>
property name="suffix" value=".jsp"/>
bean>
beans>
package com.why.Controller;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.Controller;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
* @program: SpringMVC
* @description:
* @author: @why
* @create: 2020-09-01 22:35
**/
public class TestController implements Controller {
@Override
public ModelAndView handleRequest(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws Exception {
ModelAndView view = new ModelAndView();
//相当于setAttribute
view.addObject("test","why");
//跳转到指定页面
view.setViewName("jump");
return view;
}
}