数据库建立表格
/*======================= 使用MLDN数据库 =======================*/
USE mldn ;
/*======================= 删除user数据表 =======================*/
DROP TABLE IF EXISTS user ;
/*======================= 创建user数据表 =======================*/
CREATE TABLE user(
userid VARCHAR(30) PRIMARY KEY ,
name VARCHAR(30) NOT NULL ,
password VARCHAR(32) NOT NULL
) ;
/*======================= 插入测试数据 =======================*/
INSERT INTO user (userid,name,password) VALUES ('admin','某某某','admin') ;
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>登录界面</title>
</head>
<body>
<center>
<form action="login_check.jsp" method="post">
<table border="1">
<tr colspan="2">
<td>用户登录</td>
</tr>
<tr>
<td>登录 ID:</td>
<td><input type="text" name="id"></td>
</tr>
<tr>
<td>登录密码:</td>
<td><input type="password" name="password"></td>
</tr>
<tr colspan="2">
<td><input type="submit" value="提交"></td>
<td><input type="reset" value="重置"></td>
</tr>
</table>
</form>
</center>
</body>
</html>
<%@ page language="java" contentType="text/htm;" pageEncoding="utf-8"%>
<%@ page import="java.sql.*"%>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
<%!
public static final String DBDRIVER = "org.gjt.mm.mysql.Driver" ;
public static final String DBURL ="jdbc:mysql://localhost:3306/fmz?useUnicode=true&characterEncoding=utf-8" ;
public static final String DBUSER = "root" ;
public static final String DBPASS = "mysqladmin" ;
%>
<%
Connection conn = null ;
PreparedStatement pstmt = null ;
ResultSet rs = null ;
boolean flag = false ;
String name = null ;
%>
<%
try{
Class.forName(DBDRIVER) ;
conn = DriverManager.getConnection(DBURL,DBUSER,DBPASS) ;
String sql = "SELECT name FROM user WHERE userid = ? AND password=?" ;
pstmt = conn.prepareStatement(sql) ;
pstmt.setString(1,request.getParameter("id")) ;
pstmt.setString(2,request.getParameter("password")) ;
rs = pstmt.executeQuery() ;
if(rs.next()){
name = rs.getString(1) ;
flag = true ;
}
%>
<%
}catch(Exception e){
System.out.println(e) ;
}finally{
try{
rs.close() ;
pstmt.close() ;
conn.close() ;
}catch(Exception e){
System.out.println(e) ;
}
}
%>
<%
if(flag){
%>
<jsp:forward page="login_success.jsp">
<jsp:param name="uname" value="<%=name%>"/>
</jsp:forward>
<%
}else{
%>
<jsp:forward page="login_failure.html"/>
<%
}
%>
</body>
</html>
<%@ page contentType="text/html" pageEncoding="utf-8"%>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
<center>
<h2>登录成功</h2>
<h2>欢迎<font color="red"><%=request.getParameter("uname")%></font>光临!<h2>
</center>
</body>
</html>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
<h2>登录失败,请<a href="login.html">重新登录</a></h2>
</body>
</html>
jdbc链接mysql数据库,在显示中文时,出现乱码,目前还没有解决。