與資料庫相連的代碼:
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@page import="java.sql.*"%>
<!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 name1=request.getParameter("name");
String password1=request.getParameter("password");
//注冊JDBC
Class.forName("com.mysql.jdbc.Driver");
//打開鏈接
Connection conn =(Connection) DriverManager.getConnection("jdbc:mysql://localhost:3306/mysqljdbc","root","root");
Statement stmt = (Statement)conn.createStatement();
String sql=("select * from t_test");
ResultSet rs =stmt.executeQuery(sql);
if(rs.next())
{
int id=rs.getInt("id");
String usname=rs.getString("name");
String uspassword=rs.getString("password");
if(name1.equals(usname)&&password1.equals(uspassword))
{
response.sendRedirect("denglu.jsp");
}
else{
response.sendRedirect("dlsuccess.jsp");
}
}
rs.close();
conn.close();
%>
</body>
</html>
登錄界面:
<%@ 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>登錄頁面</title>
</head>
<body>
<form method="post" action="shujuku.jsp">
用戶名:<input type="text" name="name"><br>
密碼:<input name="password" type="password"><br>
<input type="submit" value="https://bbs.csdn.net/topics/登錄" >
<input type="reset" value="https://bbs.csdn.net/topics/重置"><br>
</form>
</body>
</html>
可以注冊到資料庫里,就是登陸有問題。登錄只能跳到dlsuccess.jsp.
uj5u.com熱心網友回復:
求各位大神,救救孩子吧轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/82232.html
標籤:Eclipse
上一篇:hashmap原始碼分析后疑慮
