<JSP>习题05

<%--
  Created by IntelliJ IDEA.
  User: Lenovo
  Date: 2023/4/5
  Time: 15:20
  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>
<form>
    <h3>请选择您需要的课程</h3><br>
    <input type="checkbox" name="course" value="网络编程JSP">网络编程JSP
    <input type="checkbox" name="course" value="Android应用开发">Android应用开发
    <input type="checkbox" name="course" value="数据库原理">数据库原理<br>
    <input type="submit">
</form>
<%
    request.setCharacterEncoding("utf-8");
    String[] courses = request.getParameterValues("course");
    StringBuilder sb = new StringBuilder();
    if (courses != null) {
        String username = (String) session.getAttribute("username");
        if (username != null) {
            out.print("您好" + username + ", 您选的课程是:");
            for (String cours : courses) {
                out.print(cours + " ");
            }
        } else {
            out.print("<script>alert('您还未登录,请先登录')</script>");
        }
    }
%>
<a href="login.jsp">去登录</a>&nbsp;
</body>
</html>
<%--
  Created by IntelliJ IDEA.
  User: Lenovo
  Date: 2023/4/5
  Time: 15:41
  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>
<%
    request.setCharacterEncoding("utf-8");
    String username = request.getParameter("username");
    String password = request.getParameter("password");
    if ("jjy".equals(username) && "123".equals(password)) {
        session.setAttribute("username", username);
        response.sendRedirect("course.jsp");
    } else {
        out.print("<script>alert('您的输入有误');window.history.go(-1)</script>");
    }
%>
</body>
</html>
<%--
  Created by IntelliJ IDEA.
  User: Lenovo
  Date: 2023/4/5
  Time: 15:25
  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>
<form action="dologin.jsp" method="post">
    用户名:
    <input type="text" name="username"><br>
    密码:
    <input type="password" name="password"><br>
    <input type="submit">
</form>

</body>
</html>

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值