暴躁的田

导航

第六周

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page language="java" import="java.util.*"%>
<%@ page import ="java.sql.*"%>
<html>
<head>
<title>内容收集界面</title>
</head>
<body>
<%--<%--%>

<%
PreparedStatement pre = null;
Statement sql;
ResultSet rs;
request.setCharacterEncoding("utf-8");
String Name = request.getParameter("uname"); //获取输入的用户名
String Ps = request.getParameter("upwd"); // 密码
Name.trim();
Ps.trim();
request.setCharacterEncoding("utf-8");

Class.forName("com.mysql.jdbc.Driver");
// 建立连接
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/mysql?serverTimezone=GMT", "root", "123456");
sql =conn.createStatement();
String SQL = "select * from users where uname=? and password=?";
pre=conn.prepareStatement(SQL);
pre.setString(1,Name);
pre.setString(2,Ps);
rs=pre.executeQuery();
if (rs.next()) {
String name = rs.getString(1);
session.setAttribute("name",name);
%><p>欢迎登陆:<%=name%></p><%
}else{%> <p>输入错误,请重新登录</p><a href="register.jsp"><button>返回登录界面</button></a>
<%
}
rs.close();
sql.close();
conn.close();
%>

</body>
</html>

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>register</title>
<style type="text/css" ></style>
</head>
<body>

<form action="login.jsp" method="post">
    用户名:<input type="text" name="uname"><br>&nbsp; 码:<input type="password" name="upwd"><br>
    <input type="submit" value="提交">
</form>
    
</body>
</html>

 

 

posted on 2021-04-11 22:15  田智源  阅读(29)  评论(0编辑  收藏  举报