给你一个例子 照这做 不过现在都用springmvc+mybaits+spring 用框架了 有什么问题联系我
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
QQ登录页面
账户:
密码:
验证码
登录
注册
//实现注册功能
<%@page import="java.sql.PreparedStatement"%>
<%@page import="java.sql.Connection"%>
<%@page import="java.sql.DriverManager"%>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
request.setCharacterEncoding("utf-8");
String name = request.getParameter("name");
String password = request.getParameter("password");
Class.forName("com.mysql.jdbc.Driver");
String url = "jdbc:mysql:///mysql_01";
String usename = "root";
String usepasword ="root";
Connection conn = DriverManager.getConnection(url , usename , usepasword);
String sql ="insert into worker values(null,?, ?)";
PreparedStatement ps = conn.prepareStatement(sql);
ps.setString(1,name);
ps.setString(2,password);
ps.executeUpdate();
conn.close();
response.sendRedirect("list.jsp");
%>
//从数据库中获取所有用户数据
<%@page import="java.sql.ResultSet"%>
<%@page import="java.sql.PreparedStatement"%>
<%@page import="java.sql.Connection"%>
<%@page import="java.sql.DriverManager"%>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
数据列表
返回主页面
//实现对数据的删除功能
<%@page import="java.sql.PreparedStatement"%>
<%@page import="java.sql.Connection"%>
<%@page import="java.sql.DriverManager"%>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String id =request.getParameter("name");
Class.forName("com.mysql.jdbc.Driver");
String url = "jdbc:mysql:///mysql_01";
String usename = "root";
String usepassword ="root";
Connection conn = DriverManager.getConnection(url,usename , usepassword);
String sql = "delete from worker where id="+id;
PreparedStatement ps = conn.prepareStatement(sql);
ps.executeUpdate();
conn.close();
response.sendRedirect("list.jsp");
%>
//数据库实现对要修改的数据的查询
<%@page import="java.sql.PreparedStatement"%>
<%@page import="java.sql.Connection"%>
<%@page import="java.sql.DriverManager"%>
<%@page import="java.net.ConnectException"%>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
request.setCharacterEncoding("utf-8");
String id = request.getParameter("id");
String password = request.getParameter("password");
Class.forName("com.mysql.jdbc.Driver");
String url = "jdbc:mysql:///mysql_01";
String usename ="root";
String usepassword ="root";
Connection conn = DriverManager.getConnection(url,usename,usepassword);
String sql = "update worker set password=? where id=?";
PreparedStatement ps = conn.prepareStatement(sql);
ps.setString(1,password);
ps.setInt(2,Integer.parseInt(id));
ps.executeUpdate();
conn.close();
response.sendRedirect("list.jsp");
%>
//找到数据库中对应的要修改的数据,并对其进行修改
<%@page import="java.sql.ResultSet"%>
<%@page import="java.sql.PreparedStatement"%>
<%@page import="java.sql.Connection"%>
<%@page import="java.sql.DriverManager"%>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
request.setCharacterEncoding("utf-8");
String id = request.getParameter("name");
Class.forName("com.mysql.jdbc.Driver");
String url = "jdbc:mysql:///mysql_01";
String usename ="root";
String usepassword ="root";
Connection conn = DriverManager.getConnection(url,usename , usepassword);
String sql ="select * from worker where id=?";
PreparedStatement ps = conn.prepareStatement(sql);
//将字符串的id转换成int型的id
ps.setInt(1, Integer.parseInt(id));
ResultSet rs= ps.executeQuery();
if(rs.next()){
%>
">
密码:">
修改
<%
}
%>
//登录功能实现从前端获取的数据与数据库的数据进行对比
<%@page import="java.sql.ResultSet"%>
<%@page import="java.sql.PreparedStatement"%>
<%@page import="java.sql.DriverManager"%>
<%@page import="java.sql.Connection"%>
<%@page pageEncoding="utf-8" %>
<%
String name = request.getParameter("name");
String password = request.getParameter("password");
Class.forName("com.mysql.jdbc.Driver");
String url = "jdbc:mysql://localhost:3306/mysql_01";
String servername = "root";
String serverpassword = "root";
Connection conn = DriverManager.getConnection(url , servername , serverpassword);
String sql = "select * from worker";
PreparedStatement ps = conn.prepareStatement(sql);
ResultSet rs = ps.executeQuery();
boolean flag = false;
while(rs.next()){
if(name!=null&&(rs.getString("name")).equals(name)){
if(password!=null&&(rs.getString("password")).equals(password)){
flag = true ;
break;
}else{
flag = false;
}
}else{
flag = false;
}
}
//对flag进行判断
if(flag){
%>
<br>
window.location="login.jsp";<br>
<%
}else{
%>
<br>
window.location="Client.jsp";<br>
<%
}
%>
//跳转登录成功页面
<%@page pageEncoding="utf-8" %>
登录成功