第八周作业

1.

<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
 
<html>
  <head>   
    <title></title>
  </head> 
  <body>
  <form name="loginForm" action="login.jsp" method="post">
  账号:<input type="text" name="uname"><br>
  密码:<input type="password" name="password"> <br>
  <input type="submit" value="登录" onclick="v()">
  </form> 
  </body>
</html>
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
 
<html>
  <head>   
    <title></title>
  </head> 
  <body>
   <%
        request.setCharacterEncoding("utf-8");
        String uname = request.getParameter("uname");
        String password = request.getParameter("password");
        if (uname.equals(password)) {
            session.setAttribute("uname", uname);
            request.getRequestDispatcher("1.main.jsp").forward(request, response);
        } else {
            response.sendRedirect("1.false.jsp");
        }
    %>
  </body>
</html>
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
 
<html>
  <head>   
    <title></title>
  </head> 
  <body>
   <%
    session.invalidate();
    response.setHeader("refresh", "5;url=1.login.jsp");
  %>
退出成功!
  </body>
</html>

  

<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
 
<html>
  <head>   
    <title></title>
  </head> 
  <body>
     登陆失败!
    <%
      response.setHeader("refresh", "5;url=1.login.jsp");
    %>
  </body>
</html>

 

 2.

<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
   
    <title>My JSP 'main.jsp' starting page</title>

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

    <%
        String uname = (String) session.getAttribute("uname");
        if (uname == null)
            response.sendRedirect("login.jsp");
            
    %>
    
    <form action="show.jsp" method="post">
        商品:<br> <br>
    苹果 ¥9.9<input type="checkbox" name="item" value="苹果">加入购物车 <br> 
    橙子 ¥7.88 <input type="checkbox" name="item" value="橙子"> 加入购物车 <br> 
    桔子 ¥6.88<input type="checkbox" name="item" value="桔子"> 加入购物车<br>
    <br> 
    <input type="submit" value="加入购物车"> 
    </form> 
    <form name="form1" action="logout.jsp" method="post">
    <input type="submit" value="退出登录"> 
    </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>My JSP 'show.jsp' starting page</title>
   
  </head>
  
  <body>
   <%
    request.setCharacterEncoding("utf-8");
    String itemName[]=request.getParameterValues("item");
    if(itemName==null){
    out.print("未添加购物车");
    }
    else{
    for(int i=0;i<itemName.length;i++){
    out.print("("+(i+1)+")"+itemName[i]+"<br>");
    }
    }
   %>
    
  </body>
</html>

 

 

 

 

 

 

 

 

 

posted @ 2022-04-24 17:09  cccccccU-  阅读(6)  评论(0编辑  收藏  举报