第八周

<%--
  Created by IntelliJ IDEA.
  User: 97442
  Date: 2022/4/24
  Time: 20: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>
  <form name="formName" action="dologin.jsp" method="post">

    <input name="uname"><br>
    <input type="password" name="password"><br>
    <input type="button" value="登录" onclick="login()">
  </form>
  <script type="text/javascript">
    function login(){
      if(formName.uname.value==""||formName.password.value==""){
        alert("账号或密码不能为空!");
        return;
      }
      formName.submit();
    }
  </script>
  </body>
</html>
<%--
  Created by IntelliJ IDEA.
  User: 97442
  Date: 2022/4/24
  Time: 20:07
  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>
<%
    String uname = request.getParameter("uname");
    String password = request.getParameter("password");
    if (uname.equals(password)) {
        session.setAttribute("uname", uname);
        request.getRequestDispatcher("main.jsp").forward(request,
                response);
    } else {
%>
<script type="text/javascript">
    alert("登录失败");
</script>
<%
        request.getRequestDispatcher("login.jsp").forward(request,
                response);
    }
%>
</body>
</html>
<%--
  Created by IntelliJ IDEA.
  User: 97442
  Date: 2022/4/24
  Time: 20:07
  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>
<%
    String uname = request.getParameter("uname");
    String password = request.getParameter("password");
    if (uname.equals(password)) {
        session.setAttribute("uname", uname);
        request.getRequestDispatcher("main.jsp").forward(request,
                response);
    } else {
%>
<script type="text/javascript">
    alert("登录失败");
</script>
<%
        request.getRequestDispatcher("login.jsp").forward(request,
                response);
    }
%>
</body>
</html>
<%--
  Created by IntelliJ IDEA.
  User: 97442
  Date: 2022/4/24
  Time: 20:08
  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>
<%session.invalidate(); %>
<script type="text/javascript">
    window.location.href="main.jsp";
</script>
</body>
</html>

 

 2.

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
    String uname = (String) session.getAttribute("uname");
    if (uname == null) {
        response.sendRedirect("login.jsp");
    } else {

        out.print("欢迎" + uname + "登录!");
    }
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title></title>
</head>
<body>
    <a href="login.jsp">退出登录</a>
    <form action="car.jsp" method="post">
        <table border="1" width="600px" height="300px">
            <thead>
                <tr>
                    <th>商品名称</th>
                    <th>价格</th>
                    <th>加购</th>
                </tr>
            </thead>
            <tbody>
                <tr>
                    <td>橙子</td>
                    <td>5</td>
                    <td><input type="checkbox" name="gw" value="橙子"></td>
                </tr>
                <tr>
                    <td>西瓜</td>
                    <td>2</td>
                    <td><input type="checkbox" name="gw" value="西瓜"></td>
                </tr>
                <tr>
                    <td>苹果</td>
                    <td>1</td>
                    <td><input type="checkbox" name="gw" value="苹果"></td>
                </tr>
                <tr>
                    <td colspan="3"><input type="submit" value="加购"></td>
                </tr>
            </tbody>
        </table>
    </form>
</body>
</html>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <title></title>
  </head>
  <body>
      <%session.invalidate();%>
      <script type="text/javascript">
          window.location.href="main.jsp";
      </script>
  </body>
</html>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <title></title>
  </head>
  <body>
      <h2>购物车:</h2>
        <%
          request.setCharacterEncoding("UTF-8");
          String[] gw = request.getParameterValues("gw");
          if(gw == null){
              out.print("购物车为空!");
          }else{
              for(int i = 0; i < gw.length; i++){
                  out.print(gw[i]+"<br>");
              }
          }
       %>
  </body>
</html>

 

posted @ 2022-04-24 20:33  董梦坤  阅读(11)  评论(0编辑  收藏  举报