5月17日作业

在昨天作业的基础之上,使用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>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值