在昨天作业的基础之上,使用EL+JSTL 替换项目中的 JSP代码
index.jsp:
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page import="org.apache.catalina.User" %><%--
Created by IntelliJ IDEA.
User: 小琳爱吃火锅
Date: 2022/5/17
Time: 21:05
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>Title</title>
</head>
<body>
<%
User user = (User) session.getAttribute("user");
pageContext.setAttribute("user", user);
%>
<h1>
<c:choose>
<c:when test="${user!=null}">
<c:out value="登录成功!!! ${user.username}"></c:out>
<form action="logout" method="post">
<input type="submit" value="退出">
</form>
</c:when>
<c:when test="${user==null}">
<h1><a href="login.jsp">请登录</a></h1><br>
<h1><a href="register.jsp">注册</a></h1>
</c:when>
</c:choose>
</h1>
>
</body>
</html>
login.jsp:
<%--
Created by IntelliJ IDEA.
User: 小琳爱吃火锅
Date: 2022/5/17
Time: 21:37
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>登录页面</title>
</head>
<body>
<form action="login" method="post">
用户名:<input type="text" name="username"> <br>
密码: <input type="password" name="password"><br>
<input type="submit" value="登录"><br>
<span style="color:greenyellow">
${empty error ? "": error }
</span>
</form>
</body>
</html>
register.jsp:
<%--
Created by IntelliJ IDEA.
User: 小琳爱吃火锅
Date: 2022/5/17
Time: 21:39
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>注册页面</title>
</head>
<body>
<form action="register" method="post">
用户名: <input type="text" name="username"><br>
密 码: <input type="password" name="password"><br>
电话:<input type="text" name="telephone"><br>
生 日:<input type="date" name="birthday"><br>
性 别:<input type="radio" name="sex" value="男" checked>男
<input type="radio" name="sex" value="女">女
<br>
<input type="submit" value="注册">
<span style="color: red">
${empty error ? "": error }
</span>
</form>
</body>
</html>