Conn.java
package cn.cheen.utils;
import java.sql.*;
public class Conn {
public static Connection getConnection(){
Connection conn=null;
try{
Class.forName("com.mysql.jdbc.Driver");
String url="jdbc:mysql://localhost:3306/toyfun?useUnicode=true&characterEncoding=UTF-8";
String user="root";
String password="x5";
conn=DriverManager.getConnection(url,user,password);
}catch(Exception e){
e.printStackTrace();
}
return conn;
}
public static void release(Connection conn){
if(conn!=null)
try{
conn.close();
}catch(SQLException e){
e.printStackTrace();
}
}
public static void release(PreparedStatement pstmt){
if(pstmt!=null)
try{
pstmt.close();
}catch(SQLException e){
e.printStackTrace();
}
}
public static void release(ResultSet rs){
if(rs!=null)
try{
rs.close();
}catch(SQLException e){
e.printStackTrace();
}
}
}
JSP页面
使用JSTL需要JSP页面头部写入
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
form部分 login.jsp
<form action="Login" method="post">
<div class="form-group col-md-4 col-md-offset-4">
<input class="form-control" type="text" name="username" value="" placeholder="用户名">
</div>
<div class="form-group col-md-4 col-md-offset-4">
<input class="form-control" type="password" name="password" value="" placeholder="密码">
</div>
<div class="col-md-4 col-md-offset-4" style="text-align: center;">
<input class="btn btn-primary" type="submit" value="登录">
</div>
<div class="col-md-12" style="text-align: center;">
<span><font color="red">${loginms }</font></span>
<h3></h3>
</div>
<div class="col-md-12" style="text-align: center; margin-top: 10px;">
<a href="index.jsp">忘记密码?</a> <a href="register.jsp">前去注册</a>
</div>
</form>
register.jsp