JSP第六次作业

1.

<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<!DOCTYPE HTML>
<html>
  <head>    
    <title></title>
  </head>
  <body>
   <form  name="form" action="2.jsp" method="post">
      用户名:<input type="text" name="uname"><br>
      密码:<input type="password" name="upwd"><br>
    <input type="submit" value="登录" >    
    </form>
  </body>
</html>

  

<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<!DOCTYPE HTML>
<html>
  <head>    
    <title></title> 
  </head>
  <body>
     <%
    String uname=request.getParameter("uname");
    String upwd=request.getParameter("upwd");
    if(uname.equals(upwd)){
        session.setAttribute("uname", uname);
        request.getRequestDispatcher("3.jsp").forward(request,response);
    }else{
    request.getRequestDispatcher("4.jsp").forward(request,response);
    }
     %>
  </body>
</html>

  

<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<!DOCTYPE HTML>
<html>
  <head>    
    <title></title>  
  </head>
  <body>
    <h1>登陆成功!</h1>

    <%
        String uname = (String) session.getAttribute("uname");
        if (uname == null)
            response.sendRedirect("1.jsp");       
    %>
    <form name="form1" action="5.jsp" method="post">
    <input type="submit" value="退出登录">
    </form> 
  </body>
</html>

  

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

  

<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<!DOCTYPE HTML>
<html>
  <head>    
    <title>logout</title>
  </head>
  <body>
    <%
    session.invalidate();
    response.setHeader("refresh", "5;url=1.jsp");
     %>
  </body>
</html>

  

 

 

 

 

 

2.

<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<!DOCTYPE HTML>
<html>
  <head>    
    <title></title>
  </head>
  <body>
   <form  name="form" action="2.jsp" method="post">
      用户名:<input type="text" name="uname"><br>
      密码:<input type="password" name="upwd"><br>
    <input type="submit" value="登录" >    
    </form>
  </body>
</html>

  

<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<!DOCTYPE HTML>
<html>
  <head>    
    <title></title> 
  </head>
  <body>
     <%
    String uname=request.getParameter("uname");
    String upwd=request.getParameter("upwd");
    if(uname.equals(upwd)){
        session.setAttribute("uname", uname);
        request.getRequestDispatcher("3.jsp").forward(request,response);
    }else{
    request.getRequestDispatcher("4.jsp").forward(request,response);
    }
     %>
  </body>
</html>

  

<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<!DOCTYPE HTML>
<html>
  <head>    
    <title></title>  
  </head>
  <body>
    <h1>登陆成功!</h1>

    <%
        String uname = (String) session.getAttribute("uname");
        if (uname == null)
            response.sendRedirect("1.jsp");       
    %>
    <form action="6.jsp" method="post">
        商品:<br> <br>
        衣服<input type="checkbox" name="item" value="yifu">加入购物车 <br> 
        裤子<input type="checkbox" name="item" value="kuzi">加入购物车 <br> 
        裙子<input type="checkbox" name="item" value="qunzi">加入购物车<br><br>
    <input type="submit" value="加入购物车">
    </form>
    <form name="form1" action="5.jsp" method="post">
    <input type="submit" value="退出登录">
    </form> 
  </body>
</html>

  

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

  

<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<!DOCTYPE HTML>
<html>
  <head>    
    <title>logout</title>
  </head>
  <body>
    <%
    session.invalidate();
    response.setHeader("refresh", "5;url=1.jsp");
     %>
  </body>
</html>

  

<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<!DOCTYPE HTML>
<html>
  <head>    
    <title></title>  
  </head>
  <body>
    <%
    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 13:40  MaLD  阅读(16)  评论(0编辑  收藏  举报