zoukankan      html  css  js  c++  java
  • 编写JSP 实现用户登录并判断用户或密码

    1、登录页代码

    <%@ page language="java" contentType="text/html; charset=UTF-8"
        pageEncoding="UTF-8"%>
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>Insert title here</title>
    </head>
    <body>
    <form action="zhuye.jsp" method="post">
    <input type="text" name="name">
    <br>
    <input type="password" name="password">
    <br>
    <input type="submit" value="提交">
    
    </form>
    </body>
    </html>
    

     

    2、判断页代码

    <%@ page language="java" contentType="text/html; charset=UTF-8"
        pageEncoding="UTF-8"%>
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>Insert title here</title>
    </head>
    <body>
    <%
    String name=request.getParameter("name");
    String password=request.getParameter("password");
    %>
    <% 
    if(name.equals("name")&&password.equals("asd123456"))
    {
        out.print("输入正确");
    	
    
    }else{%>
    	<jsp:forward page="cuowuye.jsp"></jsp:forward>
    <% }%>
    
    
    
    </body>
    </html>
    

     3、跳转到的错误页代码并3秒后跳回登录页

    <%@ page language="java" contentType="text/html; charset=UTF-8"
        pageEncoding="UTF-8"%>
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>Insert title here</title>
    </head>
    <body>
    输入错误
    <%
    response.setHeader("refresh", "3;URL=shuruye.jsp");
    %> </body> </html>

     4、运行结果

    (1)输入正确时运行结果

    (2)输入错误时,运行结果

  • 相关阅读:
    LeetCode.1(两数之和)
    LeetCode.56(合并区间)
    c++ 数字与字符串的相互转换
    软件工程作业-面向对象方法学
    linux终端下解决you need to be root to perform this command
    vue中 v-bind 与 v-model的区别
    vue的核心:虚拟DOM 和 diff 算法
    弱实体集的必要性、属性随笔
    Ubuntu 18.04下Intel SGX应用程序程序开发——获得OCALL调用的返回值
    Ubuntu 18.04 INTEL SGX 修改案例打印Hello Enclave
  • 原文地址:https://www.cnblogs.com/jakeasd/p/5614719.html
Copyright © 2011-2022 走看看