Spring MVC的配置使用(不使用注解)

流程:

Spring MVC的配置使用(不使用注解)_第1张图片

Spring MVC的配置使用(不使用注解)_第2张图片

1.配置spring MVC开发环境

---引入ioc,webmvc开发包

---src中添加applicationContext.xml配置文件

2.编写Controller

public class HelloController implements Controller{
@Override
public ModelAndView handleRequest(HttpServletRequest request,
HttpServletResponse response) throws Exception {
ModelAndView mav = new ModelAndView();
mav.setViewName("hello");
mav.getModel().put("msg", "模型数据");
return mav;
}

}

3.编写hello.jsp

<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>


 
 
  
 
    <%=request.getAttribute("msg") %>
 

4.配置web.xml(配置DispatcherServlet)


    springmvc
    org.springframework.web.servlet.DispatcherServlet
   
      contextConfigLocation
      classpath:applicationContext.xml
   

    1
 

 
    springmvc
    *.do

 

5.配置applicationContext.xml(配置handlermapping、HelloController、ViewResolver)


   

     
        helloController
     

   
 
 
 
   
   

 

6.实现效果

Spring MVC的配置使用(不使用注解)_第3张图片

你可能感兴趣的:(spring技术)