zoukankan      html  css  js  c++  java
  • Java Web ClassProgram_1

    问题描述:

    简单的web登录程序

    实现代码

    jiemian.html

    <!DOCTYPE html>
    <html>
    <head>
    <meta charset="UTF-8">
    <title>Insert title here</title>
    </head>
    <body>
    <form action="shujuku.jsp" method="post">
    User Log<br>
    UserName<input type="text" name="name">
    <br>
    PassWord<input type="password" name="passWord">
    <input type="submit" name="submit" value="log">

    </form>
    </body>
    </html>

    shujuku.jsp

    <%@page import="java.sql.*"%>
    <%@ 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>
    <%
    try{
    System.out.print("跳入");
    Class.forName("com.mysql.jdbc.Driver");
    String url = "jdbc:mysql://localhost:3306/test";
    String username = "******";
    String password = "******";

    String user_name=request.getParameter("name");
    String user_pass=request.getParameter("passWord");
    System.out.println(user_name+" "+user_pass);

    if(user_name==""||user_pass==""){
    out.print("name or pass can't be null");

    }else{
    Connection conn=DriverManager.getConnection(url, username, password);
    if(conn!=null){
    out.print("database success");
    Statement sm=conn.createStatement();
    ResultSet rs=sm.executeQuery("select * from class where userName='"+user_name+"' and userPass='"+user_pass+"'");
    if(rs.next()){
    response.sendRedirect("chenggong.html");
    }
    else{
    response.sendRedirect("shibai.html");
    }
    conn.close();
    }
    else{
    out.print("数据库连接失败");
    }

    }


    }
    catch(Exception e){
    e.printStackTrace();
    }
    %>
    </body>
    </html>

    chenggong.html

    <!DOCTYPE html>
    <html>
    <head>
    <meta charset="UTF-8">
    <title>Insert title here</title>
    </head>
    <body>
    <h1>成功</h1>
    </body>
    </html>

    shibai.html

    <!DOCTYPE html>
    <html>
    <head>
    <meta charset="UTF-8">
    <title>Insert title here</title>
    </head>
    <body>
    <h1>失败</h1>
    </body>
    </html>

  • 相关阅读:
    leetcode 77 组合
    leetcode 40组合总和 II
    leetcode 216 组合总和III
    弹性伸缩 AS(Auto Scaling)
    弹性计算服务(Elastic Compute Service) / 云服务器 ECS
    云计算概述
    Zabbix Proxy 分布式监控
    Zabbix 自动发现 & 自动注册
    LVS-DR 模式
    GoAccess 监控工具
  • 原文地址:https://www.cnblogs.com/zhanghengstdu/p/6512039.html
Copyright © 2011-2022 走看看