1.p78-p79的例4-9

<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <title>My JSP 'index.jsp' starting page</title>
  </head>
  <body bgcolor=#9370DB >
    <%double price=98.78; %>
    <p style="font-family:宋体;font-size:36;color:Thistle">
    商品编号A1001,价格8765
    <a href="two.jsp?id=A1001&price=8765">购买</a><br>
    商品编号A1002,价格<%=price %>
    <a href="two.jsp?id=A1002&price=<%=price %>">购买</a>
  </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 'two.jsp' starting page</title>
  </head>
  <body bgcolor=#FFB6C1>
  <p style="font-family:宋体;font-size:36;color:blue">
    <%
    String id=request.getParameter("id");
    String price=request.getParameter("price");
     %>
     <b>商品编号:<%=id %></b><br>
     商品价格:<%=price %>
     </p>
  </body>
</html>

jsp第七周作业-LMLPHP

 jsp第七周作业-LMLPHP

 jsp第七周作业-LMLPHP

 2.p97实验2计算器

<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>p79实验2计算器</title>
</head>
<body>
    <form action="three.jsp" method="post">
        输入运算数,选择运算符号<br>
        <br> <input type="text" name="d1" value="4">
        <select name="fu">
            <option>+</option>
            <option>-</option>
            <option>*</option>
            <option>/</option>
        </select> <input type="text" name="d2" value="23"><br>
        <br> <input type="submit" name="ti" 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>计算器</title>
</head>
<body>
    <%
        request.setCharacterEncoding("utf-8");
        String d1 = request.getParameter("d1");
        String d2 = request.getParameter("d2");
        String fu = request.getParameter("fu");
        if (d1 == null || d1.length() == 0) {
            response.sendRedirect("index.jsp");
            return;
        } else if (d2 == null || d2.length() == 0) {
            response.sendRedirect("index.jsp");
            return;
        }
        try {
            double a = Double.parseDouble(d1);
            double b = Double.parseDouble(d2);
            double r = 0;
            if (fu.equals("+"))
                r = a + b;
            else if (fu.equals("-"))
                r = a - b;
            else if (fu.equals("*"))
                r = a * b;
            else if (fu.equals("/"))
                r = a / b;
            out.print(a + "" + fu + "" + b + "=" + r);
        } catch (Exception e) {
            out.println("请输入数字字符");
        }
    %>
</body>
</html>

jsp第七周作业-LMLPHP

 jsp第七周作业-LMLPHP

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

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

<%@ 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>
    <form action="four.jsp" method="post" name="form1">
        账号:<input type="text" name="name"><br>
        <br> 密码:<input type="password" name="password"><br>
        <br><input type="checkbox" name="vip" value="欢迎您注册为会员">是否注册为会员<br>
        <br> <input type="button" name="ti" value="提交" onclick="fu()">
    </form>
    <script type="text/javascript">
        function fu() {
            if (form1.name.value == "") {
                alert("账号不能为空");
                return;
            }
            if (form1.password.value == "") {
                alert("密码不能为空");
                return;
            }
            form1.submit();
        }
    </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>第3题</title>
</head>
<body>
    <%
        request.setCharacterEncoding("utf-8");
        String name = request.getParameter("name");
        String password = request.getParameter("password");
        String[] vip = request.getParameterValues("vip");
        if (name.equals(password)) {
        out.println("登录成功"+"<br>");
if(vip!=null){
            out.println("欢迎注册为会员");
        }

        } else {
            out.println("登录失败");
        }
    %>
</body>
</html>

jsp第七周作业-LMLPHP

 jsp第七周作业-LMLPHP

 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>欢迎</title>
</head>
<body>
    <form action="five.jsp" method="post">
        请输入一个数字:<br>
        <br> <input type="text" name="shu"><br>
        <br> <input type="submit" name="ti" 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>欢迎</title>
</head>
<body>
    <%
        request.setCharacterEncoding("utf-8");
        String shu = request.getParameter("shu");
        double a = Double.parseDouble(shu);
        for(int i=0;i<a;i++){
         out.println("欢迎"+"</br>");
        }
    %>
</body>
</html>

jsp第七周作业-LMLPHP

 jsp第七周作业-LMLPHP

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

<%@ page language="java" import="java.util.Enumeration"
    pageEncoding="utf-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>6</title>
</head>
<body>
    <form action="one6-1.jsp" method="post">
        账号:<input type="text" name="name1" /><br>
        <br> 密码:<input type="password" name="password" /><br>
        <br> <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>第6题</title>
</head>
<body>
    <%
    request.setCharacterEncoding("utf-8");
    String name1=request.getParameter("name1");
    String password=request.getParameter("password");

    if(name1.equals(password)){
        request.getRequestDispatcher("two6-1.jsp").forward(request, response);

    }
    else{
        request.getRequestDispatcher("one6-2.jsp").forward(request, response);
    }

   %>
</body>
</html>
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>第6题</title>
</head>
<body>
登录失败
</body>
</html>
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>第6题</title>
</head>
<body>
    <%
        request.setCharacterEncoding("utf-8");
        String name1 = request.getParameter("name1");
    %>
    <form action="two6-2.jsp" method="post">
        用户姓名:<input type="text" name="name2"><br>
        <br> <input type="submit" value="提交"><br>
        <br> <input type="hidden" name="name1" value="<%= name1 %>" />
    </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>第6题</title>
</head>
<body>
    <%
        request.setCharacterEncoding("utf-8");
        String name1 = request.getParameter("name1");
        String name2 = request.getParameter("name2");
        out.print("账号:" + name1 + "</br>" + "用户姓名:" + name2);
    %>
</body>
</html>

jsp第七周作业-LMLPHP

 jsp第七周作业-LMLPHP

 jsp第七周作业-LMLPHP

04-16 15:33