jsp第八周作业

1.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
  </head>
  
  
  <body>
   <form  name="form" action="dologin.jsp" method="post">
      用户名:<input type="text" name="uname"><br>
      密码:<input type="password" name="upwd"><br>
    <input type="submit" value="登录" >    
    </form>
  </body>
</html>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>My JSP 'dologin.jsp' starting page</title>

  </head>
  
  <body>
     <%
    request.setCharacterEncoding("utf-8");
    String uname=request.getParameter("uname");
    String upwd=request.getParameter("upwd");
    if(uname.equals(upwd)){
        session.setAttribute("uname", uname);
        request.getRequestDispatcher("main.jsp").forward(request,response);
    }else{
    request.getRequestDispatcher("no.jsp").forward(request,response);
    }
     %>
  </body>
</html>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">

  </head>
  
   <body>
    <h1>登陆成功!</h1>

    <%
        String uname = (String) session.getAttribute("uname");
        if (uname == null)
            response.sendRedirect("login.jsp");
            
    %>
    
    <form name="form1" action="logout.jsp" method="post">
    <input type="submit" value="退出登录">
    </form>
    
    
   
</body>
</html>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>My JSP 'no.jsp' starting page</title>

  </head>
  
 <body>
    <h1>登陆失败!!</h1>
    <%response.setHeader("refresh", "5;url=login.jsp");%>

</body>
</html>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>My JSP 'logout.jsp' starting page</title>
    
    <meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="cache-control" content="no-cache">
    <meta http-equiv="expires" content="0">    
    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
    <meta http-equiv="description" content="This is my page">
    <!--
    <link rel="stylesheet" type="text/css" href="styles.css">
    -->

  </head>
  
  <body>
      <h1>退出成功</h1>
    <%
    session.invalidate();
    response.setHeader("refresh", "5;url=login.jsp");
     %>
  </body>
</html>

 

 

 

2.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">

  </head>
  
   <body>
    <h1>登陆成功!</h1>

    <%
        String uname = (String) session.getAttribute("uname");
        if (uname == null)
            response.sendRedirect("login.jsp");
            
    %>
    <form action="buy.jsp">
         是否加入购物车?<br> <input type="checkbox" name="item" value="grape">
         葡萄 $1<br> <input type="checkbox" name="item"  value="banana">
         香蕉 $2<br> <input type="checkbox" name="item"  value="apple">
         苹果 $3<br>
         <input type="submit" value="加入购物车">
     </form>
    <form name="form1" action="logout.jsp" method="post">
    <input type="submit" value="退出登录">
    </form>
    
    
   
</body>
</html>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>My JSP 'buy.jsp' starting page</title>


  </head>
  
<body>

    <h2>购物车</h2>
    <%
        request.setCharacterEncoding("utf-8");
        String itemName[] = request.getParameterValues("item");
        if (itemName == null) {
            out.print("购物车为空");
        } else {
            for (int k = 0; k < itemName.length; k++) {
                out.print("(" + (k + 1) + ")" + itemName[k] + "<br>");
            }
        }
    %>

</body>
</html>

 

 

 

 
posted @ 2022-04-24 14:58  陈杭威  阅读(19)  评论(0编辑  收藏  举报