2018 SpringMVC 配置及使用

一、pom.xml



     org.springframework
     spring-webmvc
     5.1.0.RELEASE

二、springmvc-config.xml



    
    
    

三、web.xml

    
    
        SpringMVC
        org.springframework.web.servlet.DispatcherServlet
        
            contextConfigLocation
            classpath:springmvc-config.xml
        
        1
    
    
        SpringMVC
        
        *.xlm
    

四、LoginController.java

package com.baidu.mybatis.controller;

import com.baidu.mybatis.pojo.TbUser;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpSession;

/**
 * Created by IntelliJ IDEA.
 *
 * @author xlm
 * description:
 * date: 2018/10/15 15:51
 * version: 02.06
 * To change this template use File | Settings | File Templates.
 */
@Controller
public class LoginController {
    
    @RequestMapping("/login")
    public String login(String userName, String userUpwd) {

        session.setAttribute("userName",userName);

        session.setAttribute("userUpwd",userUpwd);

        return "redirect:/success.jsp";
    }

}

五、JSP

1.index.jsp

<%--
  Created by IntelliJ IDEA.
  User: xlm
  Date: 2018/9/29
  Time: 9:22
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" %>


    Title








    

2.success.jsp

<%--
  Created by IntelliJ IDEA.
  User: xlm
  Date: 2018/10/15
  Time: 15:59
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" %>


    成功页面



    
您的帐号为:${userName}
您的密码为:${userUpwd}

六、ResultView

1.index.jsp

2.success.jsp

2018 SpringMVC 配置及使用_第1张图片

你可能感兴趣的:(2018 SpringMVC 配置及使用)