Spring MVC 入门程序

引入 Spring-Mvc 的依赖


    org.springframework
    spring-webmvc
    4.3.10.RELEASE
``	

配置两个 "器"









`

配置前端控制器


    dispatcherServlet
    org.springframework.web.servlet.DispatcherServlet

    
        contextConfigLocation
        classpath:applicationContext.xml
    



    dispatcherServlet
    *.action

编写处理器

/**
 * 处理器
 */
@Controller
public class MyController01 {
    @RequestMapping("/func1.action")
    public ModelAndView func1() {
        System.out.println("func1..");
        ModelAndView modelAndView = new ModelAndView("index02.jsp");
        modelAndView.addObject("username", "admin");
        return modelAndView;
    }
}

编写视图

<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" %>
    

    index02


    ${username}


你可能感兴趣的:(Spring MVC 入门程序)