javaweb第一次作业

4.2

获取信息


<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>获取FORM表单信息</title>
</head>
<body>
<form action="output.jsp" method="post">
    <table border=1>
        <tr>
            <td>姓名:</td>
            <td><input type="text" name="name"/></td>
        </tr>

        <tr>
            <td>性别:</td>
            <td><input type="radio" name="sex" value="男" >男
                <input type="radio" name="sex" value="女">女
            </td>
        </tr>
        <tr>
            <td>爱好</td>
            <td>
                <input type="checkbox" name="hobby" value="篮球" >篮球
                <input type="checkbox" name="hobby" value="旅游">旅游
                <input type="checkbox" name="hobby" value="音乐">音乐
                <input type="checkbox" name="hobby" value="摄影">摄影

            </td>
        </tr>
        <tr>
            <td>E-mail:</td>
            <td style="width: 350px"><input type="text" name="E-mail"/></td>
        </tr>
        <tr>
            <td></td>
            <td>
                <input type="submit" value="Submit"/>
                <input type="reset" value="全部重写">
            </td>
        </tr>

    </table>
</form>

</body>
</html>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>用户输入信息</title>
</head>
<body>
<form>
    <table border="1">
        <tr>
            <td>姓名:</td>
            <td style="width: 350px">
                <%=new String(request.getParameter("name").getBytes("ISO_8859_1"),"UTF-8")%>
            </td>
        </tr>
        <tr>
            <td>性别:</td>
            <td>
                <%=new String(request.getParameter("sex").getBytes("ISO_8859_1"),"UTF-8")%>
            </td>
        </tr>
        <tr>
            <td>爱好:</td>
            <td>
                <%
                    String[] like =request.getParameterValues("hobby");
                    for (int i = 0; i < like.length; i++){
                %>
                <%=new String(like[i].getBytes("ISO_8859_1"),"UTF-8")+"&nbsp;&nbsp;"%>
                <%}%>
            </td>
        </tr>
        <tr>
            <td>E-mail:</td>
            <td>
                <%=new String(request.getParameter("E-mail"))%>
            </td>
        </tr>

    </table>
</form>

</body>
</html>


4.5

登录验证

<%@ page contentType="text/html;charset=UTF-8" language="java"  pageEncoding="UTF-8" %>
<%
    String str = request.getParameter("username");
    String pwd = request.getParameter("pwd");
    if(str!=null){
        if(str.equals("tom") && pwd.equals("123")){
            out.println("您好,tom!");
        }
        else{
            out.println("您的账号密码有误,请重新输入。");
        }
    }
%>
<html>
<head>
    <meta http-equiv="Content-Type" content ="text/html;charset=UTF-8">
    <title>Work2</title>
</head>
<body>
<form action="work1.jsp" method="post">
    账号:<input type="text" name="username"/><br/>
    密码:<input type="password" name="pwd"/><br/>
    <input type="submit" value="登录"/>
</form>
</body>
</html>

work1.jsp

<%
    String str = request.getParameter("username");
    String pwd = request.getParameter("pwd");
    String username = str;

    if(str!=null) {
        if (str.equals("tom") && pwd.equals("123")) {
            out.println("您好,tom!");


        } else {
            out.println("您的账号密码有误,请重新输入。");
        }
        response.sendRedirect("work2.jsp");
    }




%>
<html>
<head>
    <meta http-equiv="Content-Type" content ="text/html;charset=UTF-8">
    <title>Work1</title>
</head>
<body>
<form action="work1.jsp" method="post">
    账号:<input type="text" name="username"/><br/>
    <%String name = request.getParameter("username");
        session.setAttribute("session_name",name);
    %>
    密码:<input type="password" name="pwd"/><br/>
    <input type="submit" value="登录"/>
</form>
</body>
</html>

work2.jsp

<%String name1 = (String) session.getAttribute("session_name");

    if (name1!=null){
        out.println("欢迎您"+name1);
    }
    else{
        out.println("欢迎您,"+name1+"非正常访问");
    }
%>
<html>
<head>
    <title>title</title>
</head>
<body>


</body>
</html>

经过登录页面是,会跳转到

当不经过登录页面是

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

花荣04

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值