其他分享
首页 > 其他分享> > JSP_homework_04_0406

JSP_homework_04_0406

作者:互联网

作业1:

<%--
  Created by IntelliJ IDEA.
  User: 音无彩名
  Date: 2022/4/10
  Time: 0:13
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>regist</title>
    <style type="text/css">
        span {
            color: red;
        }
    </style>
    <script type="text/javascript">
        window.onload = function() {
            var flag1 = false;
            var flag2 = false;
            var flag3 = false;
            var flag4 = false;
            document.getElementById("username").onblur = function() {
                if (!/^[0-9a-zA-Z]{4,16}$/.test(document.getElementById("username").value)) {
                    flag1 = false;
                    document.getElementById("checkText").innerText = "用户名输入不合法";
                } else {
                    flag1 = true;
                    document.getElementById("checkText").innerText = "";
                }
            }
            document.getElementById("password").onblur = function() {
                if (!/^[0-9a-zA-Z]{6,12}$/.test(document.getElementById("password").value)) {
                    flag2 = false;
                    document.getElementById("checkPassword").innerText = "密码输入不合法";
                } else {
                    flag2 = true;
                    document.getElementById("checkPassword").innerText = "";
                }
            }
            document.getElementById("rePassword").onblur = function(){
                if(document.getElementById("password").value !== document.getElementById("rePassword").value){
                    flag3 = false;
                    document.getElementById("checkRePassword").innerText = "两次输入不一致";
                } else {
                    flag3 = true;
                    document.getElementById("checkRePassword").innerText = "";
                }
            }
            document.getElementById("email").onblur = function(){
                if(!/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/.test(document.getElementById("email").value)){
                    flag4 = false;
                    document.getElementById("checkEmail").innerText = "邮箱格式错误";
                } else{
                    flag4 = true;
                    document.getElementById("checkEmail").innerText = "";
                }
            }
        }
    </script>
</head>
<body>
<form action="/JSPHomework/homework0406/test1/show.jsp">
    <table border="0px" cellspacing="" cellpadding="">
        <tr>
            <td>用户名:</td>
            <td><input type="text" name="username" id="username" value="" />只能输入字母或数字,4-16个字符</td>
            <td><span id="checkText"></span></td>
        </tr>
        <tr>
            <td>密码:</td>
            <td><input type="password" name="password" id="password">密码长度6-12位</td>
            <td><span id="checkPassword"></span></td>
        </tr>
        <tr>
            <td>确认密码:</td>
            <td><input type="password" id="rePassword" /></td>
            <td><span id="checkRePassword"></span></td>
        </tr>
        <tr>
            <td>性别:</td>
            <td><input type="radio" name="sex" id="sex1" value="男" checked="" /> 男
                <input type="radio" name="sex" id="sex0" value="女" /> 女 </td>
        </tr>
        <tr>
            <td>电子邮件地址:</td>
            <td><input type="email" name="email" id="email" value="" /> 请输入正确的邮件地址</td>
            <td><span id="checkEmail"></span></td>
        </tr>
        <tr>
            <td>出生日期:</td>
            <td><input type="date" name="date" id="date" /></td>
        </tr>
        <tr>
            <td></td>
            <td><input type="submit" id="submit" value="同意以下协议条款并提交" /></td>
        </tr>
        <tr>
            <td colspan="2"><textarea rows="10" cols="50">一,总则 1.1用户应当同意本协议的条款并按照界面上的提示完成全部注册程序,以下省略..
                    ...........................................................................</textarea></td>
        </tr>
    </table>
</form>
</body>
</html>
<%--
  Created by IntelliJ IDEA.
  User: 音无彩名
  Date: 2022/4/10
  Time: 0:41
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%
    String username = request.getParameter("username");
    String password = request.getParameter("password");
    String sex = request.getParameter("sex");
    String email = request.getParameter("email");
    String date = request.getParameter("date");
%>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>show</title>
    <style type="text/css">
        tr{
            font-size: 30px;
            color: deeppink;
        }
    </style>
</head>
<body>
<table border="0px" cellspacing="" cellpadding="">
    <tr>
        <th colspan="2">您注册的信息如下:</th>
    </tr>
    <tr>
        <td>用户名:</td>
        <td><%=username%></td>
    </tr>
    <tr>
        <td>密码:</td>
        <td><%=password%></td>
    </tr>
    <tr>
        <td>性别:</td>
        <td><%=sex%></td>
    </tr>
    <tr>
        <td>电子邮件:</td>
        <td><%=email%></td>
    </tr>
    <tr>
        <td>出生日期:</td>
        <td><%=date%></td>
    </tr>
</table>
</body>
</html>

 

作业2:

<%--
  Created by IntelliJ IDEA.
  User: 音无彩名
  Date: 2022/4/10
  Time: 2:28
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>input</title>
    <style type="text/css">
        table {
            font-size: 30px;
        }
    </style>
</head>
<body>
<form action="<%=request.getContextPath()%>/homework0406/test2/out.jsp">
    <table border="0px" cellspacing="" cellpadding="">
        <tr>
            <th colspan="2">求平均值:</th>
        </tr>
        <tr>
            <td>姓名:</td>
            <td><input type="text" name="name" id="name" /> </td>
        </tr>
        <tr>
            <td>性别:</td>
            <td>男:<input type="radio" name="sex" id="sex1" value="男" checked="" />
                女:<input type="radio" name="sex" id="sex0" value="女" /> </td>
        </tr>
        <tr>
            <td>班级:</td>
            <td><select name="class" id="class">
                <option value="1901">1901</option>
                <option value="1902">1902</option>
            </select> </td>
        </tr>
        <tr>
            <td>语文:</td>
            <td><input type="number" name="chinese" id="chinese" min="0" max="100" /> </td>
        </tr>
        <tr>
            <td>数学:</td>
            <td><input type="number" name="math" id="math" min="0" max="100" /></td>
        </tr>
        <tr>
            <td>英语:</td>
            <td><input type="number" name="english" id="english" min="0" max="100" /></td>
        </tr>
        <tr>
            <td><input type="submit" value="提交" /> </td>
            <td><input type="button" id="clear" value="重设" onclick="javascript:parent.location.reload()" /> </td>
        </tr>
    </table>
</form>
</body>
</html>
<%--
  Created by IntelliJ IDEA.
  User: 音无彩名
  Date: 2022/4/10
  Time: 2:28
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%
    String name = request.getParameter("name");
    String clazz = request.getParameter("class");
    String sex = request.getParameter("sex");
    Double chinese = Double.valueOf(request.getParameter("chinese"));
    Double math = Double.valueOf(request.getParameter("math"));
    Double english = Double.valueOf(request.getParameter("english"));
    Double avg = (chinese + math + english) / 3.0;
%>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>out</title>
    <style type="text/css">
        table{
            font-size: 30px;
            color: coral;
        }
    </style>
</head>
<body>
<table border="0px" cellspacing="" cellpadding="">
    <tr>
        <th colspan="2">您好!<%=clazz%>班的<%=name%>同学!</th>
    </tr>
    <tr>
        <td>性别</td>
        <td><%=sex%></td>
    </tr>
    <tr>
        <td>您的各科成绩平均分是</td>
        <td><%=avg%></td>
    </tr>
</table>
</body>
</html>

 

 

————————————————————————————————————————

————————

 

..

 安

 

 

标签:function,false,04,value,getElementById,innerText,JSP,document,homework
来源: https://www.cnblogs.com/cotomi/p/16124622.html