JSP_3.26第四周作业

1. login.jsp

<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://"
            + request.getServerName() + ":" + request.getServerPort()
            + path + "/";
%>

<html> <script> function yzm(){ var Num=""; for(var i=0;i<4;i++) { Num+=Math.floor(Math.random()*10); } document.getElementById("yzphoto").value=Num; document.getElementById("yzm").value=Num; } function userLogin(){ var yztext = document.getElementById("yztext").value; var yzm = document.getElementById("yzm").value; location.reload(); } </script> <style> body { text-align: "center" } #div1 { margin: 15% auto; } </style> </head> <body onLoad="yzm()"> <div id="div1"> <h2 style=color:"blue">用 户 登 录</h2> <form action="dologin.jsp" name="myform" method="post"> 用户名: <input type="text" name="uname"><br /> 密 码: <input type="password" name="upwd"><br /> 验证码: <input id="yztext" type="text" value="" /> <input style="width:50px;background-color:red;color:blue" type="text" id="yzphoto" value="" /> <input type="hidden" id="yzm" value=""> <br /> <br /> <input type="submit" style=color:"blue" value=" 登&nbsp&nbsp&nbsp&nbsp录 "> </form> </div> </body> </html>

2.  dologin.jsp

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

<%
    //获取登录的用户名
    String name = request.getParameter("uname");
    //获取登录密码
    String pwd = request.getParameter("upwd");
    //判断

    if (name.equals("zs") && pwd.equals("123"))
        //转发到ok页面
        request.getRequestDispatcher("ok.jsp").forward(request,response);
    else
        //转发到no页面 
        request.getRequestDispatcher("no.jsp").forward(request,response);
%>

3.  ok.jsp

<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>My JSP 'index.jsp' starting page</title>
    <meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="cache-control" content="no-cache">
    <meta http-equiv="expires" content="0">    
    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
    <meta http-equiv="description" content="This is my page">
    <!--
    <link rel="stylesheet" type="text/css" href="styles.css">
    -->
    <style>
    body{text-align:"center"}
    #div1{margin:15% auto;}
    </style>
  </head>
  
  <body>
  <div id="div1">
   <h2>提示信息:</h2>
   <h1 style="color: red">登录成功</h1>
  </div>
   
  </body>
</html>

4.  no.jsp

<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://"
            + request.getServerName() + ":" + request.getServerPort()
            + path + "/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">

<title>My JSP 'index.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
    <link rel="stylesheet" type="text/css" href="styles.css">
    -->
<style>
body {
    text-align: "center"
}

#div1 {
    margin: 15% auto;
}
</style>
</head>

<body>
    <div id="div1">
        <h2>提示信息:</h2>
        <h1 style="color: red">登录失败</h1>
        <input type="button" value="返回登录界面" onClick="showValue(dologin.jsp)" />
    </div>
</body>
</html>

posted @ 2021-03-29 14:50  熊大To  阅读(50)  评论(0编辑  收藏  举报