完成登录程序,可进行注册,需进行头像的上传,登录成功之后,可进行注销和进行个人信息修改,并且可以修改头像。
公共方法:
文件自动取名FileNameAuto
package cn.lizhi.pub;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
public class FileNameAuto {
private String ip;
public String getIp() {
return ip;
}
public void setIp(String ip) {
this.ip = ip;
}
public FileNameAuto(String ip) {
super();
this.ip = ip;
}
public FileNameAuto() {
super();
}
public String getFileName(){
Date date = new Date();
DateFormat df = new SimpleDateFormat("yyyyMMddHHmmssSSS");
String fileName = df.format(date);
return fileName;
}
}
获取表ID GetTableID
package cn.lizhi.pub;
import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.DriverManager;
public class GetTableID {
public static final String DRIVER = "oracle.jdbc.driver.OracleDriver";
public static final String URL = "jdbc:oracle:thin:@10.211.55.3:1521:orcl";
public static final String USERNAME = "lizhi";
public static final String PASSWORD = "lizhi";
public static int getIdk() {
Connection conn = null;
CallableStatement cstate = null;//专门用于调用存储过程和函数的操作接口
int result_ = 0;
try {
Class.forName(DRIVER);
conn = DriverManager.getConnection(URL,USERNAME,PASSWORD);
//调用存储过程
String sql = "{? = call getidk}";
cstate = conn.prepareCall(sql);
cstate.registerOutParameter(1, java.sql.Types.INTEGER);//定义返回值的类型
cstate.execute();//执行
result_ = cstate.getInt(1);//取得返回值
} catch (Exception e) {
e.printStackTrace();
} finally{
try {
cstate.close();
conn.close();
} catch (Exception e2) {
e2.printStackTrace();
}
}
return result_;
}
}
注册账号检查 RegisterCheck
package cn.lizhi.pub;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
public class RegisterCheck {
public static final String DRIVER = "oracle.jdbc.driver.OracleDriver";
public static final String URL = "jdbc:oracle:thin:@10.211.55.3:1521:orcl";
public static final String USERNAME = "lizhi";
public static final String PASSWORD = "lizhi";
Connection conn = null;
PreparedStatement pstate = null;
ResultSet res = null;
public boolean checkUserName(String userName) {
boolean flag = true;
try {
String sql = "select count(user_id) from dh12_user where user_account= ?";
pstate = conn.prepareStatement(sql);
pstate.setString(1, userName);
res = pstate.executeQuery();
while(res.next()){
int count = res.getInt(1);
if(count > 0){
flag = false;
}
}
} catch (Exception e) {
e.printStackTrace();
} finally{
try{
res.close();
pstate.close();
}catch(Exception e2){
e2.printStackTrace();
}
}
return flag;
}
}
用户保存进数据库 SaveUser
package cn.lizhi.pub;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
public class SaveUser {
public static final String DRIVER = "oracle.jdbc.driver.OracleDriver";
public static final String URL = "jdbc:oracle:thin:@10.211.55.3:1521:orcl";
public static final String USERNAME = "lizhi";
public static final String PASSWORD = "lizhi";
public static int saveuser(String userName,String password,String userImg) {
Connection conn = null;
PreparedStatement pstate = null;
int flag = -1;
try {
Class.forName(DRIVER);
conn = DriverManager.getConnection(URL,USERNAME,PASSWORD);
String sql = "insert into dh12_user(USER_ID,USER_ACCOUNT,USER_PASSWORD,USER_IMG) values(?,?,?,?)";
pstate = conn.prepareStatement(sql);
pstate.setInt(1,GetTableID.getIdk());
pstate.setString(2,userName);
pstate.setString(3,password);
pstate.setString(4,userImg);
pstate.execute();
flag = 1;
} catch (Exception e) {
e.printStackTrace();
} finally{
try {
pstate.close();
conn.close();
} catch (Exception e2) {
e2.printStackTrace();
}
}
return flag;
}
}
用户类 UserBean
package cn.lizhi.pub;
public class UserBean
{
private String userAccount;
private String password;
private String Img;
private String name;
public String getUserAccount() {
return userAccount;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public void setUserAccount(String userAccount) {
this.userAccount = userAccount;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getImg() {
return Img;
}
public void setImg(String img) {
Img = img;
}
public UserBean(String userAccount, String password, String img) {
super();
this.userAccount = userAccount;
this.password = password;
this.name = name;
Img = img;
}
public UserBean() {
super();
// TODO Auto-generated constructor stub
}
}
登陆:Login.jsp
<%@page import="java.text.Normalizer.Form"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ page import="java.sql.*"%>
<%
String account = "";
String password = "";
%>
<!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>
<style type=