package com.vodka.Controller;
import com.vodka.Entity.UserInfo;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
@Controller
public class ModelController {
@ModelAttribute
public void MyModel(@RequestParam(required = false)String node, Model model){
model.addAttribute("Nodes",node);
}
@ModelAttribute("NodeName")
public String StringModel(@RequestParam(required = false)String MyNode ,Model model){
return MyNode;
}
@RequestMapping(value = "/TestModel")
public String TestModel(){
return "ModelTest";
}
@RequestMapping(value="/ModelTestSecond")
public String ModelTestSecond(@ModelAttribute("UInfo") UserInfo userInfo){
if("vodka".equals(userInfo.getName()) && "lwjsfdsf".equals(userInfo.getPwd()) ){
return "Login";
}
return "Register";
}
}
index.jsp
<%@ page contentType="text/html;charset=UTF-8" language="java" pageEncoding="utf-8" %>
<html>
<body>
<a href="${pageContext.request.contextPath}/Login?name=vodka&pwd=lwj888">登录界面</a> <br>
<a href="${pageContext.request.contextPath}/Register">注册界面</a> <br>
<a href="${pageContext.request.contextPath}/TestModel?node=One&MyNode=VodkaNode">Model</a> <br>
<a href="${pageContext.request.contextPath}/ModelTestSecond?Name=vodka&Pwd=lwj888">ModelTestSecond</a> <br>
</body>
</html>
ModelTest.jsp
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>Model Test</title>
</head>
<body>
<h1>Model Test</h1>
<p>Nodes: ${Nodes}</p>
<p>NodeName: ${NodeName}</p>
</body>
</html>
Register.jsp
<%@ page contentType="text/html;charset=UTF-8" language="java" pageEncoding="UTF-8" %>
<html>
<head>
<title>注册界面</title>
</head>
<body>
<h1>欢迎${sessionScope.get("name")}来到注册界面</h1>
</body>
</html>
Login.jsp
<%@ page contentType="text/html;charset=UTF-8" language="java" pageEncoding="utf-8" %>
<%--必须引入的jstl核心--%>
<%@ taglib prefix="v" uri="http://java.sun.com/jsp/jstl/core"%>
<html>
<head>
<title>登录界面</title>
</head>
<body>
<v:if test="${Trial=='false'}">
<h1>登录失败!</h1> <br>
<v:forEach items="${ErrorList}" var="error">
<h1>${error}</h1> <br>
</v:forEach>
</v:if>
<v:if test="${Trial=='true'}">
<h1>登录成功!</h1> <br>
<v:forEach items="${NameList}" var="name">
<h1>欢迎${name}来到登录界面</h1>
</v:forEach>
</v:if>
</body>
</html>