JSP+Servlet+JavaBean写用户登录注册

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


                
  • 4
    点赞
  • 23
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值