第七周作业

 

1.教材P78-79 例4-9

 

<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Insert title here</title>
</head>
<body bgcolor=#ffccff>
    <%
        double p = 98.78;
    %>
    <p>商品编号A1001,价格 8765</p>
    <a href="receive.jsp?id=A1001&price=8765">购买</a>
    <p>商品编号A1002,价格</p>
    <a href="receive.jsp?id=A1002&price=<%=p%>">购买</a>
</body>
</html>

 

 

 

<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Insert title here</title>
</head>
<body bgcolor=#eeeeff>
    <%
        String id = request.getParameter("id");
        String price = request.getParameter("price");
    %>
    <b>商品编号:<%=id%></b>
    <br>
    <b>商品价格:<%=price%></b>
</body>
</html>

 

 

 2.教材P97 实验2

 

<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Insert title here</title>
</head>
<body bgcolor=#ffccff>
    <form action="computer.jsp" method=post>
        <p>
            输入运算数,选择运算符号:<br> <input type=text name="no" size=6 /> <select
                name="oa">
                <option selected="selected" value="+"><option value="-"><option value="*"><option value="/"></select> <input type=text name="nt" size=6 /> <br> <input type="submit"
                name="submit" value="提交">
        </p>
    </form>
</body>
</html>

 

 

 

 

 

 

 

<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Insert title here</title>
</head>
<body bgcolor=cyan>
    <p>
        <%
            String no = request.getParameter("no");
            String nt = request.getParameter("nt");
            String oa = request.getParameter("oa");
            if (no == null || no.length() == 0) {
                response.sendRedirect("input.jsp");
                return;
            } else if (nt == null || nt.length() == 0) {
                response.sendRedirect("input.jsp");
                return;
            }
            try {
                double a = Double.parseDouble(no);
                double b = Double.parseDouble(nt);
                double r = 0;
                if (oa.equals("+")) {
                    r = a + b;
                } else if (oa.equals("-")) {
                    r = a - b;
                } else if (oa.equals("*")) {
                    r = a * b;
                } else if (oa.equals("/")) {
                    r = a / b;
                }
                out.print(a + oa + b + "=" + r);
            } catch (Exception e) {
 
            }
        %>
    </p>
</body>
</html>

 

 

 3.制作一个登陆表单,输入账号和密码,如果账号密码相同,跳转到“登录成功”页面,否则跳转到“登录失败”页面。(加上JS非空验证)(选做,加验证码)

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


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
   

  </head>
  
  <body>
  <form action="Login1.jsp"method="post">
 请输入账号:<input name="account"type="text"><br>
 
 请输入密码:<input name="password"type="password"><br>
<input type="submit"value="登陆">
</form>

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


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
   
  </head>
  
  <body>
<% String account=request.getParameter("account");
String password=request.getParameter("password");
if(account.equals(password)){
response.sendRedirect("welcome.jsp");
}else{
out.print("登录错误"); 
}%>
  </body>
</html>
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
   
  </head>
  
  <body>

<%out.print("登陆成功,欢迎来到本系统"); %> <br>
  </body>
</html>

 

 

 4.在上题的表单中增加一个checkbox,让用户选择“是否注册为会员",如果注册为会员,则在显示时增加文本“欢迎您注册为会员”。

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


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
   

  </head>
  
  <body>
  <form action="Login1.jsp"method="post">
 请输入账号:<input name="account"type="text"><br>
 
 请输入密码:<input name="password"type="password"><br>
 是否注册会员
  <input type="checkbox" name="huiyuan" value="yes"><input type="checkbox" name="huiyuan" value="no"><br>
<input type="submit"value="登陆"><br>

</form>

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


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
   
  </head>
  
  <body>
<% String account=request.getParameter("account");
String password=request.getParameter("password");
String huiyuan=request.getParameter("huiyuan");

if(account.equals(password)){
out.print("注册成功");
 }else if(account.equals(password)&&huiyuan.equals("yes"))
       {out.print("欢迎您成为会员!");
       }else if(account.equals(password)&&huiyuan.equals("no")) {
out.print("没有成为会员"); 
}else{
out.print("登录错误");}
%>
  </body>
</html>

 

 

 

5.在页面1的表单内输人一个数字N,提交,能够在另一个页面打印N个“欢迎”字符串。

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


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>

  <head>
   <title>在页面1的表单内输人一个数字N,提交,能够在另一个页面打印N个“欢迎”字符串</title>
  </head>
   <body>
    <form action="second.jsp">
    输入一个数:<input type="text" name="shu"><br>
    <input type="submit" value="提交">
    </form>    
  </body>

  </body>
</html>

 

 

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


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>

  </head>
  
<body>
    <%
    String shu=request.getParameter("shu");
    int n=Integer.parseInt(shu); 
    for(int i=0;i<n;i++){
    out.print("欢迎"+"!! ");
    }
     %>
  </body>
</html>

 

 

6.在页面1中输入账号和密码,进行登录,如果账号和密码相同,则认为成功登录到页面2,在页面2中显示一个文本框输人用户姓名,输人之后提交,在页面3中显示用户的账号和姓名。

<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
 
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Insert title here</title>
</head>
<body>
    <script type="text/javascript">
        function login() {
            if (formtext.caccount.value != formtext.cpassword.value) {
                alert('账号与密码不同');
                return;
            }
            formtext.submit();
        }
    </script>
 
    <form name="formtext" action="setName.jsp" method="post">
        <b>账号</b> <input type="text" name="caccount" /> <br> <b>密码</b> <input
            type="password" name="cpassword" /> <br> <input type="button"
            onclick="login()" value="登录" />
    </form>
</body>
</html>
<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Insert title here</title>
</head>
<body>
    <%
        request.setCharacterEncoding("utf-8");
    %>
    <%
        String account = request.getParameter("caccount");
    %>
 
    <form action="verificationthird.jsp" method="post">
        <b>姓名</b><input type="text" name="cname"> <input
            name="caccount" type="hidden" value="<%=account%>"> <input
            type="submit" value="登录" />
 
    </form>
 
</body>
</html>
<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Insert title here</title>
</head>
<body>
    <%
        request.getRequestDispatcher("twoShow.jsp").forward(request, response);
    %>
 
</body>
</html>
<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Insert title here</title>
</head>
<body>
    <%
        request.setCharacterEncoding("utf-8");
    %>
    <%
        String account = request.getParameter("caccount");
        String name = request.getParameter("cname");
    %>
    <h1>
        账号:<%=account%></h1>
    <h1>
        姓名:<%=name%></h1>
</body>
</html>

 

 

 

 

 

posted on 2022-04-17 12:39  咬^O^咬  阅读(9)  评论(0编辑  收藏  举报