日报 web实验

Index

<%@ page language="java" contentType="text/html; charset=UTF-8"

    pageEncoding="UTF-8"%>

<!DOCTYPE html>

<html>

<head>

<meta charset="UTF-8">

<title>主页</title>

</head>

<style>

    body

    {

         background-image: url(b.jpg);

        background-size:100% 100% ;

        background-attachment: fixed ;

    }

     table

     {

         border-spacing: 10px 20px;

        border : solid 1px red;

        margin-top:300px;

    }

    .font

    {

        letter-spacing:6px;

    }

</style>

<script type="text/jscript">

    request.setCharacterEncoding("utf-8");

    function jump(adress,a)

    {

        if(adress=='s1')

        {

            if (a=="1")

            window.location.href='login.jsp';

            if (a=="2")

            window.location.href='s1.jsp';

        }

        if(adress=='s2')

        {

            if (a=="1")

            window.location.href='login.jsp';

            if (a=="2")

            window.location.href='s2.jsp';

        }

        if(adress=='s3')

        {

        if (a=="1")

            window.location.href='login.jsp';

        if (a=="2")

            window.location.href='s3.jsp';

        }

    }

</script>

<body class = "font">

<%! String a="1";%>

<%! String b="亲爱的游客,欢迎访问本网站"; %>

<%

    Cookie[] cookies = request.getCookies();

    if(cookies != null && cookies.length > 0)

    {

        for(Cookie c: cookies)

        {

        if(c.getName().toString().equals("username"))

        {

            b = c.getValue().toString();   

        }

        if(c.getName().toString().equals("id"))

        {

                a = c.getValue().toString();   

        }

}}

 

    %>

<marquee  scrollAmount="20" direction="left" scrollDelay="90" behavior="alternate" loop="-1" onmouseover="this.stop()"

        onmouseout="this.start()"   hspace="20%">

        <a  style="color: red; font-family: 黑体; font-size: 15pt; text-align: center;"><%=b  %>   </a>

    </marquee>

<table align="center" valign="middle">

<tr> <td align="center"> <a href="javascript:jump('s1',<%=a %>)">故宫</a></td></tr>   

<tr> <td align="center"> <a href="javascript:jump('s2',<%=a %>)">颐和园</a></td></tr>

<tr> <td align="center"> <a href="javascript:jump('s3',<%=a %>)">香山</a></td></tr>

<tr> <td align="center" > <a href="login.jsp">登录</a></td></tr>

</table>

</body>

</html>

 

Login

 <%@ page language="java" contentType="text/html; charset=UTF-8"

    pageEncoding="UTF-8"%>

<!DOCTYPE html>

<html>

<head>

<meta charset="UTF-8">

<title>登录</title>

</head>

<style>

body

{

     background: url(b.jpg);

     background-size:100% 100% ;

     background-attachment: fixed

 

}

</style>

<script type="text/javascript">

    window.onload = function check( )

    {

        document.getElementById("submit_login").onclick = function()

        {

            var str1 = form1.username.value;

            var str2 = form1.password.value;

            if (str1 == ""||str2 == "") {

                alert("用户名或者密码为空!");

                form1.username.focus();

            }   

            return;

        };

    };

</script>

<body>

 

<form action="check.jsp" method="post" id="form1" name = "form1" onsubmit="">

  <table align="center" valign="middle">

  <tr><td id="top">用户登录 </td></tr>

        <tr>

            <td>用户名:</td>

            <td><input type="text" name="username"  id = "username"value=""> </td>

        </tr>

        <tr>

            <td> 密码:</td>

            <td><input type="password"  name="password" id = "password"> </td>

        </tr>

        <tr>

          <td  colspan="2" align="center"><input type="submit" value="确定" name="submit_login" id="submit_login">

            <input type="reset" > </td>

        </tr>

    </table>

    </form>

</body>

</html>

Check

<%@ page language="java" contentType="text/html; charset=UTF-8"

    pageEncoding="UTF-8"%>

<!DOCTYPE html>

<html>

<head>

<meta charset="UTF-8">

<title>Insert title here</title>

</head>

<body>

 

<%

    request.setCharacterEncoding("utf-8");//解决中文乱码的问题

    String name = request.getParameter("username");

    String password = request.getParameter("password");

    session.setAttribute("name", name);

    Cookie cookie = new Cookie("name",name);

    cookie.setMaxAge(3000); //设置cookie有效期为30s

    response.addCookie(cookie);

if(name.equals(password))

    {%>

        <h1>用户登录成功两秒后为您跳转</h1>

    <%

    response.setHeader("refresh", "2;url=s3.jsp");

    }

    else{%>   

    <h1>用户登录失败两秒后跳转请重新登录</h1>

        <% response.setHeader("refresh", "2;url=login.jsp");

    }

 

 

%>

</body>

</html>

S1

<%@ page language="java" contentType="text/html; charset=UTF-8"

    pageEncoding="UTF-8"%>

<!DOCTYPE html>

<html>

<head>

<meta charset="UTF-8">

<title>Insert title here</title>

</head>

<body>

 

<%

    request.setCharacterEncoding("utf-8");//解决中文乱码的问题

    String name = request.getParameter("username");

    String password = request.getParameter("password");

    session.setAttribute("name", name);

    Cookie cookie = new Cookie("name",name);

    cookie.setMaxAge(3000); //设置cookie有效期为30s

    response.addCookie(cookie);

if(name.equals(password))

    {%>

        <h1>用户登录成功两秒后为您跳转</h1>

    <%

    response.setHeader("refresh", "2;url=s3.jsp");

    }

    else{%>   

    <h1>用户登录失败两秒后跳转请重新登录</h1>

        <% response.setHeader("refresh", "2;url=login.jsp");

    }

 

 

%>

</body>

</html>

程序截图

 

 

 

 

 

 

 

 

 

 


 

 

posted @   秋渡晚枫  阅读(7)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· 三行代码完成国际化适配,妙~啊~
· .NET Core 中如何实现缓存的预热?
· 如何调用 DeepSeek 的自然语言处理 API 接口并集成到在线客服系统
点击右上角即可分享
微信分享提示