这个测试对我来言有些难度,短时间内做不了太多。首先是思路的理清,登录后的界面有好几种,而且公文的状态也有好几种。理清思路就花了一些时间

然后大致的框架做了做,然后将用户的增删改查还有公文的增删改查写了写。登录界面也完成了,不过不同角色登陆后的界面还没来得及做。主要就是功能太多,运用不熟练

数据库

bean层的基本信息

package com.bean;
public class User {
private int id;
private String username;
private String password;
private int permissionId;
private int status;
public int getStatus() {
return status;
}
public void setStatus(int status) {
this.status = status;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
private String job;
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public int getPermissionId() {
return permissionId;
}
public void setPermissionId(int permissionId) {
this.permissionId = permissionId;
}
public String getJob() {
return job;
}
public void setJob(String job) {
this.job = job;
} }
package com.bean;

public class Permission {
private int id;
private int permission;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public int getPermission() {
return permission;
}
public void setPermission(int permission) {
this.permission = permission;
}
}
package com.bean;

public class Doc {

    private int id;
private String tipplace;
private String ftipplace;
private int deletestatus;
private int callback;
public int getCallback() {
return callback;
}
public void setCallback(int callback) {
this.callback = callback;
}
public int getDeletestatus() {
return deletestatus;
}
public void setDeletestatus(int deletestatus) {
this.deletestatus = deletestatus;
}
public String getFtipplace() {
return ftipplace;
}
public void setFtipplace(String ftipplace) {
this.ftipplace = ftipplace;
}
public String getTipplace() {
return tipplace;
}
public void setTipplace(String tipplace) {
this.tipplace = tipplace;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
private String title;
private String owner;
private String time;
private String receiver;
private int status;
private int result;
private String place;
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getOwner() {
return owner;
}
public void setOwner(String owner) {
this.owner = owner;
}
public String getTime() {
return time;
}
public void setTime(String time) {
this.time = time;
}
public String getReceiver() {
return receiver;
}
public void setReceiver(String receiver) {
this.receiver = receiver;
}
public int getStatus() {
return status;
}
public void setStatus(int status) {
this.status = status;
}
public int getResult() {
return result;
}
public void setResult(int result) {
this.result = result;
}
public String getPlace() {
return place;
}
public void setPlace(String place) {
this.place = place;
}
}

然后是连接数据库

package com.dao;

import java.sql.*;

public class DBDao {
private static String USER = "root";
private static String PASSWORD = "123456";
private static String DB_URL = "jdbc:mysql://localhost:3306/mytest?serverTimezone=UTC";
private static String DB_DRIVER = "com.mysql.jdbc.Driver";
private static Connection connection = null; //连接数据库
public static Connection getConnection(){ try {
Class.forName(DB_DRIVER);
connection = DriverManager.getConnection(DB_URL, USER, PASSWORD);
} catch (Exception e) {
System.out.println("数据库连接异常");
e.printStackTrace();
}
return connection;
}
public static void closeConnection(Connection connection){ if(connection != null){
try {
connection.close(); // 关闭数据库连接
} catch (SQLException e) {
e.printStackTrace();
}
}
} public static void closeAll(Connection connection,PreparedStatement statement,ResultSet rSet)
{
try {
if(connection!=null)
connection.close();
} catch (SQLException e) {
// TODO 自动生成的 catch 块
e.printStackTrace();
} try {
if(statement!=null)
statement.close();
} catch (SQLException e) {
// TODO 自动生成的 catch 块
e.printStackTrace();
} try {
if(rSet!=null)
rSet.close();
} catch (SQLException e) {
// TODO 自动生成的 catch 块
e.printStackTrace();
}
} //关闭connection和preparedstatement
public static void closePart(Connection connection,PreparedStatement statement)
{
try {
if(connection!=null)
connection.close();
} catch (SQLException e) {
// TODO 自动生成的 catch 块
e.printStackTrace();
} try {
if(statement!=null)
statement.close();
} catch (SQLException e) {
// TODO 自动生成的 catch 块
e.printStackTrace();
}
}
}

DocDao层:

package com.dao;
import com.bean.*;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List; import com.bean.*;
import com.dao.DBDao;
public class DocDao { public static boolean add_doc(Doc doc)
{
Connection con=null;
PreparedStatement pstmt=null;
ResultSet rs=null;
try {
con=DBDao.getConnection();
String sql="insert into doc_list(title,owner,receiver,time,status,result,place,deletestatus,callback) values(?,?,?,?,?,?,?,?,?)";
pstmt=con.prepareStatement(sql);
pstmt.setString(1, doc.getTitle());
pstmt.setString(2, doc.getOwner());
pstmt.setString(3, doc.getReceiver());
pstmt.setString(4, doc.getTime());
pstmt.setInt(5, doc.getStatus());
pstmt.setInt(6, doc.getResult());
pstmt.setString(7, doc.getPlace());
pstmt.setInt(8, 0);
pstmt.setInt(9, 0);
pstmt.executeUpdate();
return true;
}
catch (SQLException e) {
System.out.println("注册失败");
e.printStackTrace();
}
finally {
DBDao.closeAll(con, pstmt, rs);
}
return false;
} //删除数据
@SuppressWarnings("resource")
public static boolean sendDoc(int id)
{
Connection con=null;
PreparedStatement pstmt=null;
ResultSet rSet=null;
int status=-1;
int newstatus=-1;
String receiver="";
try {
con=DBDao.getConnection();
String sql_query="select * from doc_list where id="+id;
pstmt=con.prepareStatement(sql_query);
rSet=pstmt.executeQuery();
if(rSet.next())
{
status=rSet.getInt("status");
}
switch (status) {
case 0:
newstatus=1;
receiver="副厂长";
break;
case 2:
newstatus=5;
receiver="厂长";
break;
case 3:
newstatus=4;
receiver="部门";
break;
case 6:
newstatus=8;
receiver="部门和副厂长";
break;
case 7:
newstatus=9;
receiver="部门和副厂长";
break;
case 8:
newstatus=10;
receiver="部门";
break;
default:
System.out.println("公文状态有误!");
break;
}
String sql_update="update doc_list set status = ? where id = ?";
pstmt=con.prepareStatement(sql_update);
pstmt.setInt(1, newstatus);
pstmt.setInt(2, id);
pstmt.executeUpdate();
return true;
}
catch (SQLException e) {
System.out.println("数据库信息更新失败");
e.printStackTrace();
}
finally {
DBDao.closePart(con, pstmt);
}
return false;
} public static ArrayList<Doc> getDocesByCase(String type,String value)
{
Connection connection=null;
PreparedStatement preparedStatement=null;
ResultSet rSet=null;
try {
connection=DBDao.getConnection();
String sql="";
System.out.println(type);
if(type.equals("title"))
{
sql="select * from doc_list where title='"+value+"'";
}
else if(type.equals("owner"))
{
sql="select * from doc_list where owner='"+value+"'";
}
else if(type.equals("receiver"))
{
sql="select * from doc_list where receiver='"+value+"'";
}
else if(type.equals("result"))
{
sql="select * from doc_list where result='"+value+"'";
}
preparedStatement=connection.prepareStatement(sql);
rSet=preparedStatement.executeQuery();
ArrayList<Doc> list=new ArrayList<>();
while(rSet.next())
{
Doc doc=new Doc();
doc.setId(rSet.getInt("id"));
doc.setTitle(rSet.getString("title"));
doc.setOwner(rSet.getString("owner"));
doc.setTime(rSet.getString("time"));
doc.setReceiver(rSet.getString("receiver"));
doc.setStatus(rSet.getInt("status"));
doc.setResult(rSet.getInt("result"));
doc.setPlace(rSet.getString("place"));
list.add(doc);
}
return list;
} catch (SQLException e) {
// TODO: handle exception
e.printStackTrace();
}
finally {
DBDao.closeAll(connection, preparedStatement, rSet);
}
return null;
} public static ArrayList<Doc> getCheckedorNot(String type)
{
Connection connection=null;
PreparedStatement preparedStatement=null;
ResultSet rSet=null;
try {
connection=DBDao.getConnection();
String sql="";
System.out.println(type);
if(type.equals("notchecked"))
{
sql="select * from doc_list where status=1";
}
else
{
sql="select * from doc_list where status!=1 and status!=0 and status!=-1";
}
preparedStatement=connection.prepareStatement(sql);
rSet=preparedStatement.executeQuery();
ArrayList<Doc> list=new ArrayList<>();
while(rSet.next())
{
Doc doc=new Doc();
doc.setId(rSet.getInt("id"));
doc.setTitle(rSet.getString("title"));
doc.setOwner(rSet.getString("owner"));
doc.setTime(rSet.getString("time"));
doc.setReceiver(rSet.getString("receiver"));
doc.setStatus(rSet.getInt("status"));
doc.setResult(rSet.getInt("result"));
doc.setPlace(rSet.getString("place"));
list.add(doc);
}
return list;
} catch (SQLException e) {
// TODO: handle exception
e.printStackTrace();
}
finally {
DBDao.closeAll(connection, preparedStatement, rSet);
}
return null;
} public static ArrayList<Doc> getFcheckedorNot(String type)
{
Connection connection=null;
PreparedStatement preparedStatement=null;
ResultSet rSet=null;
try {
connection=DBDao.getConnection();
String sql="";
if(type.equals("checked"))
{
sql="select * from doc_list where status=6 or status=7";
}
else
{
sql="select * from doc_list where status=5";
}
preparedStatement=connection.prepareStatement(sql);
rSet=preparedStatement.executeQuery();
ArrayList<Doc> list=new ArrayList<>();
while(rSet.next())
{
Doc doc=new Doc();
doc.setId(rSet.getInt("id"));
doc.setTitle(rSet.getString("title"));
doc.setOwner(rSet.getString("owner"));
doc.setTime(rSet.getString("time"));
doc.setReceiver(rSet.getString("receiver"));
doc.setStatus(rSet.getInt("status"));
doc.setResult(rSet.getInt("result"));
doc.setPlace(rSet.getString("place"));
list.add(doc);
}
return list;
} catch (SQLException e) {
// TODO: handle exception
e.printStackTrace();
}
finally {
DBDao.closeAll(connection, preparedStatement, rSet);
}
return null;
} public static ArrayList<Doc> getReceivedByUser(String type,User user)
{
Connection connection=null;
PreparedStatement preparedStatement=null;
ResultSet rSet=null;
try {
connection=DBDao.getConnection();
String sql="";
if(type.equals("received"))
{
sql="select * from doc_list where owner=? and status=10";
}
else
{
sql="select * from doc_list where owner=? and status!=10";
}
preparedStatement=connection.prepareStatement(sql);
preparedStatement.setString(1, user.getUsername());
rSet=preparedStatement.executeQuery();
ArrayList<Doc> list=new ArrayList<>();
while(rSet.next())
{
Doc doc=new Doc();
doc.setId(rSet.getInt("id"));
doc.setTitle(rSet.getString("title"));
doc.setTime(rSet.getString("time"));
doc.setStatus(rSet.getInt("status"));
doc.setResult(rSet.getInt("result"));
list.add(doc);
}
return list;
} catch (SQLException e) {
// TODO: handle exception
e.printStackTrace();
}
finally {
DBDao.closeAll(connection, preparedStatement, rSet);
}
return null;
} public static Doc getDocById(Doc doc)
{
Connection connection=null;
PreparedStatement preparedStatement=null;
ResultSet rSet=null;
try {
connection=DBDao.getConnection();
String sql="select * from doc_list where id="+doc.getId();
preparedStatement=connection.prepareStatement(sql);
rSet=preparedStatement.executeQuery();
if(rSet.next())
{
doc.setTitle(rSet.getString("title"));
doc.setOwner(rSet.getString("owner"));
doc.setTime(rSet.getString("time"));
doc.setReceiver(rSet.getString("receiver"));
doc.setStatus(rSet.getInt("status"));
doc.setResult(rSet.getInt("result"));
doc.setPlace(rSet.getString("place"));
doc.setTipplace(rSet.getString("tipplace"));
doc.setFtipplace(rSet.getString("tipfplace"));
return doc;
}
} catch (SQLException e) {
// TODO: handle exception
e.printStackTrace();
}
finally {
DBDao.closeAll(connection, preparedStatement, rSet);
}
return null;
} public static boolean checked_change(Doc doc)
{
Connection connection=null;
PreparedStatement preparedStatement=null;
String sql_update="update doc_list set status = ?,result = ?,receiver = ?,tipplace = ? where id = ?";
try {
connection=DBDao.getConnection();
preparedStatement=connection.prepareStatement(sql_update);
preparedStatement.setInt(1, doc.getStatus());
preparedStatement.setInt(2, doc.getResult());
preparedStatement.setString(3, doc.getReceiver());
preparedStatement.setString(4, doc.getTipplace());
preparedStatement.setInt(5, doc.getId());
preparedStatement.executeUpdate();
return true;
} catch (SQLException e) {
// TODO 自动生成的 catch 块
e.printStackTrace();
}
finally {
DBDao.closePart(connection, preparedStatement);
}
return false;
} public static boolean fchecked_change(Doc doc)
{
Connection connection=null;
PreparedStatement preparedStatement=null;
String sql_update="update doc_list set status = ?,result = ?,receiver = ?,tipfplace = ? where id = ?";
try {
connection=DBDao.getConnection();
preparedStatement=connection.prepareStatement(sql_update);
preparedStatement.setInt(1, doc.getStatus());
preparedStatement.setInt(2, doc.getResult());
preparedStatement.setString(3, doc.getReceiver());
preparedStatement.setString(4, doc.getFtipplace());
preparedStatement.setInt(5, doc.getId());
preparedStatement.executeUpdate();
return true;
} catch (SQLException e) {
// TODO 自动生成的 catch 块
e.printStackTrace();
}
finally {
DBDao.closePart(connection, preparedStatement);
}
return false;
} public static boolean formatDoc(Doc doc)
{
Connection connection=null;
PreparedStatement preparedStatement=null;
String sql_update="update doc_list set status = ? where id = ?";
try {
connection=DBDao.getConnection();
preparedStatement=connection.prepareStatement(sql_update);
preparedStatement.setInt(1, doc.getStatus());
preparedStatement.setInt(2, doc.getId());
preparedStatement.executeUpdate();
return true;
} catch (SQLException e) {
// TODO 自动生成的 catch 块
e.printStackTrace();
}
finally {
DBDao.closePart(connection, preparedStatement);
}
return false;
} public static boolean ReceiveDoc(Doc doc)
{
Connection connection=null;
PreparedStatement preparedStatement=null;
String sql_update="update doc_list set status = ?,callback = 1 where id = ?";
try {
connection=DBDao.getConnection();
preparedStatement=connection.prepareStatement(sql_update);
preparedStatement.setInt(1, 10);
preparedStatement.setInt(2, doc.getId());
preparedStatement.executeUpdate();
return true;
} catch (SQLException e) {
// TODO 自动生成的 catch 块
e.printStackTrace();
}
finally {
DBDao.closePart(connection, preparedStatement);
}
return false;
} public static ArrayList<Doc> getDocByTime(Doc doc1,Doc doc2)
{
Connection connection=null;
PreparedStatement preparedStatement=null;
ResultSet rs=null;
String sql="select * from doc_list where time between ? and ?";
try {
connection=DBDao.getConnection();
preparedStatement=connection.prepareStatement(sql);
preparedStatement.setString(1,doc1.getTime());
preparedStatement.setString(2, doc2.getTime());
rs=preparedStatement.executeQuery();
ArrayList<Doc> list=new ArrayList<>();
while(rs.next())
{
Doc doc=new Doc();
doc.setId(rs.getInt("id"));
doc.setTitle(rs.getString("title"));
doc.setTime(rs.getString("time"));
doc.setOwner(rs.getString("owner"));
list.add(doc);
}
return list;
} catch (SQLException e) {
// TODO 自动生成的 catch 块
e.printStackTrace();
}
finally {
DBDao.closePart(connection, preparedStatement);
}
return null;
} public static ArrayList<Doc> getAllDoc()
{
Connection connection=null;
PreparedStatement preparedStatement=null;
ResultSet rs=null;
String sql="select * from doc_list";
try {
connection=DBDao.getConnection();
preparedStatement=connection.prepareStatement(sql);
rs=preparedStatement.executeQuery();
ArrayList<Doc> list=new ArrayList<>();
while(rs.next())
{
Doc doc=new Doc();
doc.setId(rs.getInt("id"));
doc.setTitle(rs.getString("title"));
doc.setTime(rs.getString("time"));
doc.setOwner(rs.getString("owner"));
list.add(doc);
}
return list;
} catch (SQLException e) {
// TODO 自动生成的 catch 块
e.printStackTrace();
}
finally {
DBDao.closePart(connection, preparedStatement);
}
return null;
} public static ArrayList<Permission> getPermission(Permission permission)
{
Connection connection=null;
PreparedStatement preparedStatement=null;
ResultSet rs=null;
String sql="select * from permission where id="+permission.getId();
try {
connection=DBDao.getConnection();
preparedStatement=connection.prepareStatement(sql);
rs=preparedStatement.executeQuery();
ArrayList<Permission> list=new ArrayList<>();
while(rs.next())
{
Permission permission1=new Permission();
permission1.setId(rs.getInt("id"));
permission1.setPermission(rs.getInt("permission"));
list.add(permission1);
}
return list;
} catch (SQLException e) {
// TODO 自动生成的 catch 块
e.printStackTrace();
}
finally {
DBDao.closePart(connection, preparedStatement);
}
return null;
} public static boolean deletePermission(Permission permission)
{
Connection con=null;
PreparedStatement pstmt=null;
try {
con=DBDao.getConnection();
String sql="delete from permission where id="+permission.getId();
System.out.println(sql);
pstmt=con.prepareStatement(sql);
pstmt.executeUpdate();
return true;
}
catch(SQLException e)
{
e.printStackTrace();
}
finally {
DBDao.closePart(con, pstmt);
}
return false;
} public static boolean updatePermission(Permission permission1,Permission permission2)
{
Connection con=null;
PreparedStatement pstmt=null;
try {
con=DBDao.getConnection();
String sql="update permission set permission = ? where id = ? and permission = ?";
pstmt=con.prepareStatement(sql);
pstmt.setInt(1, permission2.getPermission());
pstmt.setInt(2, permission1.getId());
pstmt.setInt(3, permission1.getPermission());
pstmt.executeUpdate();
return true;
}
catch(SQLException e)
{
e.printStackTrace();
}
finally {
DBDao.closePart(con, pstmt);
}
return false;
} public static boolean deleteDoc(Doc doc)
{
Connection con=null;
PreparedStatement pstmt=null;
try {
con=DBDao.getConnection();
String sql="update doc_list set deletestatus = ? where id = ?";
pstmt=con.prepareStatement(sql);
pstmt.setInt(1, doc.getDeletestatus());
pstmt.setInt(2, doc.getId());
pstmt.executeUpdate();
return true;
}
catch(SQLException e)
{
e.printStackTrace();
}
finally {
DBDao.closePart(con, pstmt);
}
return false;
} public static ArrayList<Doc> getCall()
{
Connection connection=null;
PreparedStatement preparedStatement=null;
ResultSet rSet=null;
try {
connection=DBDao.getConnection();
String sql="select * from doc_list where callback=1";
preparedStatement=connection.prepareStatement(sql);
rSet=preparedStatement.executeQuery();
ArrayList<Doc> list=new ArrayList<>();
while(rSet.next())
{
Doc doc=new Doc();
doc.setId(rSet.getInt("id"));
doc.setTitle(rSet.getString("title"));
doc.setOwner(rSet.getString("owner"));
doc.setTime(rSet.getString("time"));
doc.setReceiver(rSet.getString("receiver"));
doc.setStatus(rSet.getInt("status"));
doc.setResult(rSet.getInt("result"));
doc.setPlace(rSet.getString("place"));
doc.setDeletestatus(rSet.getInt("deletestatus"));
doc.setCallback(rSet.getInt("callback"));
list.add(doc);
}
return list;
} catch (SQLException e) {
// TODO: handle exception
e.printStackTrace();
}
finally {
DBDao.closeAll(connection, preparedStatement, rSet);
}
return null;
} public static boolean setCallOver(Doc doc)
{
Connection con=null;
PreparedStatement pstmt=null;
try {
con=DBDao.getConnection();
String sql="update doc_list set callback = ? where id = ?";
pstmt=con.prepareStatement(sql);
pstmt.setInt(1, 0);
pstmt.setInt(2, doc.getId());
pstmt.executeUpdate();
return true;
}
catch(SQLException e)
{
e.printStackTrace();
}
finally {
DBDao.closePart(con, pstmt);
}
return false;
} }

package com.dao;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList; import com.bean.User; public class UserDao {
User user = null;
private String SQL = ""; public User login(String username, String password,int permissionID) {
SQL = "select * from user where username = ? and password = ? and permissionID = ?";
Connection connection = null;
PreparedStatement pstmt = null;
try {
connection = DBDao.getConnection();
pstmt = (PreparedStatement) connection.prepareStatement(SQL);
// 这里的意思将用户名和密码填到SQL语句的问号处
pstmt.setString(1, username);
pstmt.setString(2, password);
pstmt.setInt(3, permissionID);
ResultSet rSet = (ResultSet) pstmt.executeQuery();//得到数据库的查询结果,一个数据集
// 判断结果集是否有效
if (rSet.next()) {
user = new User();
user.setUsername(rSet.getString("username"));
user.setPassword(rSet.getString("password"));
user.setPermissionId(rSet.getInt("permissionID"));
}
pstmt.close();
connection.close(); } catch (Exception e) { e.printStackTrace();
} finally {
DBDao.closeConnection(connection);
}
return user;
}
public static boolean delete_user(User user)
{
Connection con=null;
PreparedStatement pstmt=null;
try {
con=DBDao.getConnection();
String sql="delete from user where id="+user.getId();
System.out.println(sql);
pstmt=con.prepareStatement(sql);
pstmt.executeUpdate();
return true;
}
catch(SQLException e)
{
e.printStackTrace();
}
finally {
DBDao.closePart(con, pstmt);
}
return false;
} public static boolean update_userstatus(User user)
{
Connection con=null;
PreparedStatement pstmt=null;
try {
con=DBDao.getConnection();
String sql="update users set statu = ? where id = ?";
pstmt=con.prepareStatement(sql);
pstmt.setInt(1, user.getStatus());
pstmt.setInt(2, user.getId());
pstmt.executeUpdate();
return true;
}
catch(SQLException e)
{
e.printStackTrace();
}
finally {
DBDao.closePart(con, pstmt);
}
return false;
} public static boolean update_user(User user)
{
Connection con=null;
PreparedStatement pstmt=null;
try {
con=DBDao.getConnection();
String sql="update user set username=?,password=?,job=? where id = "+user.getId();
pstmt=con.prepareStatement(sql);
pstmt.setString(1, user.getUsername());
pstmt.setString(2, user.getPassword());
pstmt.setString(3, user.getJob());
pstmt.executeUpdate();
return true;
}
catch(SQLException e)
{
e.printStackTrace();
}
finally {
DBDao.closePart(con, pstmt);
}
return false;
}
public static ArrayList<User> getAllUser()
{
Connection connection=null;
PreparedStatement preparedStatement=null;
ResultSet rs=null;
String sql="select * from user";
try {
connection=DBDao.getConnection();
preparedStatement=connection.prepareStatement(sql);
rs=preparedStatement.executeQuery();
ArrayList<User> list=new ArrayList<>();
while(rs.next())
{
User user=new User();
user.setId(rs.getInt("id"));
user.setUsername(rs.getString("username"));
user.setPassword(rs.getString("password"));
user.setPermissionId(rs.getInt("permissionId"));
user.setJob(rs.getString("job"));
user.setStatus(rs.getInt("status"));
list.add(user);
}
return list;
} catch (SQLException e) {
// TODO 自动生成的 catch 块
e.printStackTrace();
}
finally {
DBDao.closePart(connection, preparedStatement);
}
return null;
} public static User getUserById(User user)
{
Connection connection=null;
PreparedStatement preparedStatement=null;
ResultSet rs=null;
String sql="select * from user where id="+user.getId();
try {
connection=DBDao.getConnection();
preparedStatement=connection.prepareStatement(sql);
rs=preparedStatement.executeQuery();
User user1=new User();
if(rs.next())
{
user1.setId(rs.getInt("id"));
user1.setUsername(rs.getString("username"));
user1.setPassword(rs.getString("password"));
user1.setPermissionId(rs.getInt("permissionId"));
user1.setStatus(rs.getInt("status"));
user1.setJob(rs.getString("job"));
}
return user1;
} catch (SQLException e) {
// TODO 自动生成的 catch 块
e.printStackTrace();
}
finally {
DBDao.closePart(connection, preparedStatement);
}
return null;
}
public static boolean updatePwd(User user)
{
Connection con=null;
PreparedStatement pstmt=null;
try {
con=DBDao.getConnection();
String sql="update user set password = ? where username = ?";
pstmt=con.prepareStatement(sql);
pstmt.setString(1, user.getPassword());
pstmt.setString(2, user.getUsername());
pstmt.executeUpdate();
return true;
}
catch(SQLException e)
{
e.printStackTrace();
}
finally {
DBDao.closePart(con, pstmt);
}
return false;
} public static User getUserByUsername(User user)
{
Connection connection=null;
PreparedStatement preparedStatement=null;
ResultSet rs=null;
String sql="select * from user where username='"+user.getUsername()+"'";
try {
connection=DBDao.getConnection();
preparedStatement=connection.prepareStatement(sql);
rs=preparedStatement.executeQuery();
User user1=new User();
if(rs.next())
{
user1.setId(rs.getInt("id"));
user1.setPermissionId(rs.getInt("permissionId"));
System.out.println(user1.getPermissionId());
}
return user1;
} catch (SQLException e) {
// TODO 自动生成的 catch 块
e.printStackTrace();
}
finally {
DBDao.closePart(connection, preparedStatement);
}
return null;
} }

前面是 UserDao层

登录的servlet

package com.servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import com.dao.*;
import com.bean.User; public class LoginServlet extends HttpServlet { private static final long serialVersionUID = 1L; public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setCharacterEncoding("utf-8"); // 获取用户名和密码
String username = request.getParameter("username"); String password = request.getParameter("password"); int permissionID =Integer.parseInt(request.getParameter("permissionID"));
// 获取UserDao实例
UserDao userDao = new UserDao();
User user= userDao.login(username, password, permissionID);
if(permissionID==1){
request.getRequestDispatcher("changzhang.jsp").forward(request, response);
}
else if(permissionID==2) {
request.getRequestDispatcher("fuchangzhang.jsp").forward(request, response);
}
else if(permissionID==3) {
request.getRequestDispatcher("bangongshi.jsp").forward(request, response);
}
else if(permissionID==4) {
request.getRequestDispatcher("zhuchangqu.jsp").forward(request, response);
}
else if(permissionID==5) {
request.getRequestDispatcher("yifenqu.jsp").forward(request, response);
}
else if(permissionID==6) {
request.getRequestDispatcher("erfenqu.jsp").forward(request, response);
}
else if(permissionID==7) {
request.getRequestDispatcher("sanfenqu.jsp").forward(request, response);
}
else if(permissionID==8) {
request.getRequestDispatcher("xiaoshoubumen.jsp").forward(request, response);
}
else if(permissionID==9) {
request.getRequestDispatcher("caiwubumen.jsp").forward(request, response);
}
else {
request.getRequestDispatcher("guanliyuan.jsp").forward(request, response);
} } public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doPost(request, response);
} }

公文拟制的servlet

package com.servlet;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date; import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import com.bean.Doc;
import com.dao.DocDao; /**
* Servlet implementation class writedoc
*/
@WebServlet("/writedoc")
public class Writedoc extends HttpServlet {
private static final long serialVersionUID = 1L; /**
* @see HttpServlet#HttpServlet()
*/
public Writedoc() {
super();
// TODO Auto-generated constructor stub
} /**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
response.getWriter().append("Served at: ").append(request.getContextPath());
} /**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
String text=request.getParameter("text");
String user=request.getParameter("user");
String title=request.getParameter("title");
System.out.println(text);
Date date = new Date();
SimpleDateFormat dateFormat= new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
String time=dateFormat.format(date).toString();
String path="D:\\5\\text4\\WebContent\\text\\"+title+"_"+user+"_"+time.split(":| ")[0]+time.split(":| ")[1]+time.split(":| ")[2]+time.split(":| ")[3]+".txt";
System.out.println(path);
File file = new File(path);
FileOutputStream fileOutputStream; Doc doc=new Doc();
doc.setTitle(title);
doc.setOwner(user);
doc.setReceiver("办公室");
doc.setTime(time);
doc.setStatus(-1);
doc.setResult(0);
doc.setPlace(path);
if(DocDao.add_doc(doc))
{
try {
fileOutputStream = new FileOutputStream(file);
try {
fileOutputStream.write((text).getBytes());
fileOutputStream.close();
response.getWriter().write("yes"); } catch (IOException e) {
// TODO 自动生成的 catch 块
response.getWriter().write("no");
e.printStackTrace();
} } catch (FileNotFoundException e) {
// TODO 自动生成的 catch 块
response.getWriter().write("no");
e.printStackTrace();
}
}
else
{
response.getWriter().write("no");
}
} }

签收公文:

package com.servlet;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import com.bean.Doc;
import com.dao.DocDao; /**
* Servlet implementation class Signdoc
*/
@WebServlet("/Signdoc")
public class Signdoc extends HttpServlet {
private static final long serialVersionUID = 1L; /**
* @see HttpServlet#HttpServlet()
*/
public Signdoc() {
super();
// TODO Auto-generated constructor stub
} /**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
response.getWriter().append("Served at: ").append(request.getContextPath());
} /**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
int id=Integer.parseInt(request.getParameter("id"));
System.out.println(id);
Doc doc=new Doc();
doc.setId(id);
if(DocDao.ReceiveDoc(doc))
response.getWriter().write("yes");
else
response.getWriter().write("no");
} }

发送

package com.servlet;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import com.dao.DocDao; /**
* Servlet implementation class Senddoc
*/
@WebServlet("/Senddoc")
public class Senddoc extends HttpServlet {
private static final long serialVersionUID = 1L; /**
* @see HttpServlet#HttpServlet()
*/
public Senddoc() {
super();
// TODO Auto-generated constructor stub
} /**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
response.getWriter().append("Served at: ").append(request.getContextPath());
} /**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
int id=Integer.parseInt(request.getParameter("id"));
if(DocDao.sendDoc(id))
{
response.getWriter().write("yes");
}
else
{
response.getWriter().write("no");
}
} }

删除:

package com.servlet;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import com.bean.Doc;
import com.dao.DocDao; /**
* Servlet implementation class Deletedoc
*/
@WebServlet("/Deletedoc")
public class Deletedoc extends HttpServlet {
private static final long serialVersionUID = 1L; /**
* @see HttpServlet#HttpServlet()
*/
public Deletedoc() {
super();
// TODO Auto-generated constructor stub
} /**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
response.getWriter().append("Served at: ").append(request.getContextPath());
} /**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
int id=Integer.parseInt(request.getParameter("id"));
Doc doc=new Doc();
doc.setId(id);
doc.setDeletestatus(1);
if(DocDao.deleteDoc(doc))
response.getWriter().write("yes");
else
response.getWriter().write("no");
} }

修改:

package com.servlet;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date; import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import com.bean.Doc;
import com.dao.DocDao; /**
* Servlet implementation class Updatedoc
*/
@WebServlet("/Updatedoc")
public class Updatedoc extends HttpServlet {
private static final long serialVersionUID = 1L; /**
* @see HttpServlet#HttpServlet()
*/
public Updatedoc() {
super();
// TODO Auto-generated constructor stub
} /**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
response.getWriter().append("Served at: ").append(request.getContextPath());
} /**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
int id=Integer.parseInt(request.getParameter("id"));
int result=Integer.parseInt(request.getParameter("result"));
String tip=request.getParameter("tip");
Date date = new Date();
SimpleDateFormat dateFormat= new SimpleDateFormat("yyyy-MM-dd-hh-mm-ss");
String time=dateFormat.format(date).toString();
String path="E:\\work_space\\official-document\\WebContent\\tip\\"+id+"_"+time+"_tip.txt";
File file = new File(path);
FileOutputStream fileOutputStream; int status;
if(result==0)
status=3;
else
status=2;
Doc doc=new Doc();
doc.setId(id);
doc.setResult(result);
doc.setStatus(status);
doc.setReceiver("办公室");
doc.setTipplace(path);
if(DocDao.checked_change(doc))
{
try {
fileOutputStream = new FileOutputStream(file);
try {
fileOutputStream.write((tip).getBytes());
fileOutputStream.close();
response.getWriter().write("yes"); } catch (IOException e) {
// TODO 自动生成的 catch 块
response.getWriter().write("no");
e.printStackTrace();
} } catch (FileNotFoundException e) {
// TODO 自动生成的 catch 块
response.getWriter().write("no");
e.printStackTrace();
}
}
else
response.getWriter().write("no"); } }

登录界面的jsp

<%@ page language="java" contentType="text/html; charset=utf-8"
pageEncoding="utf-8"%>
<!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">
<style>
body {
top: 20%;
text-align: center
} .div {
top: 50%;
margin: auto;
}
</style> <title>Insert title here</title> <!--判断是否为空-->
<script type="text/javascript">
function login(form) {
if (form.username.value == "") {
alert("用户不能为空!");
return false;
}
if (form.password.value == "") {
alert("密码不能为空!");
return false;
}
}
</script> </head>
<body>
<h1>登录</h1>
<hr>
<br>
<br>
<br>
<div class="div">
<form method="post" action="LoginServlet"
onSubmit="return login(this);">
<center>
<table>
<tr>
<td>用户名:</td>
<td><input type="text" name="username"></td>
</tr>
<tr>
<td>密码:</td>
<td><input type="password" name="password"></td>
</tr>
</table>
<select name="pamissionID">
<option value=1>厂长</option>
<option value=2>副厂长</option>
<option value=3>办公室</option>
<option value=4>主厂区</option>
<option value=5>一分厂</option>
<option value=6>二分厂</option>
<option value=7>三分厂</option>
<option value=8>销售部门</option>
<option value=9>财务部门</option>
<option value=10>系统管理员</option>
</select>
</center>
<br> <br> <input type="submit" value="点击登录"
style="width: 120px; height: 33px; background: #ccc; color: black">
</form>
</div> <br>
<br>
<br>
<br> </body>
</html>

网络技能大赛A卷测试的更多相关文章

  1. 【技能大赛笔记01】Zigbee点对点按键控制程序开发

    [技能大赛笔记01]Zigbee点对点按键控制程序开发 --2017年"物联网物联网技术应用与维护"任务五题1(中职组) 1.题目要求 2.工程文件 在比赛中,提供了一个基于Bas ...

  2. 2018工业信息安全技能大赛华东赛区初赛 第2题 writeup

    2018工业信息安全技能大赛华东赛区初赛 第2题 解题思路 本题主要考察点是对常见工控协议的理解(modbus/tcp和s7comm),题目目标是寻找出报文中某条异常报文流量.很让人疑惑的是,题目中并 ...

  3. 【Azure Redis 缓存 Azure Cache For Redis】在创建高级层Redis(P1)集成虚拟网络(VNET)后,如何测试VNET中资源如何成功访问及配置白名单的效果

    当使用Azure Redis高级版时候,为了能更好的保护Redis的安全,启用了虚拟网路,把Redis集成在Azure中的虚拟网络,只能通过虚拟网络VENT中的资源进行访问,而公网是不可以访问的.但是 ...

  4. 2018~第三届南宁市网络安全技术大赛~nnctf~write-up

    Web 1.超简单 分值:100 类型:WEB 已解决 题目:超简单的web题  http://gxnnctf.gxsosec.cn:12311/ 代码审计 <?php $white_list ...

  5. linux网络监控_网速测试

    Linux下查看网络即时网速 1.sar命令(一般般) sar -n DEV 1 100 1代表一秒统计并显示一次 100代表统计一百次 sar在sysstat包 2.使用ntop图形工具(没详细用过 ...

  6. ookla 网络上传下载 PING 测试

    1.登陆http://www.ookla.com/ 2.点选Explore Speedtest Custon 3. 1.start for free 或者 2.measure your network ...

  7. 信息工程学院技能大赛 计算机程序设计(Java)大赛试题

    前期准备与后期上传工作: (1)必须先建立项目和包,项目名为"JavaContest",包结构为:"contest.c+序号+姓名",其中序号为两位为本人大赛报 ...

  8. Windows平台VC++ 6.0 下的网络编程学习 - 简单的测试winsock.h头文件

    最近学习数据结构和算法学得有点累了(貌似也没那么累...)...找了本网络编程翻了翻当做打一个小基础吧,打算一边继续学习数据结构一边也看看网络编程相关的... 简单的第一次尝试,就大致梳理一下看书+自 ...

  9. 山东省网络安全技能大赛 部分writeup

    web1 提示:ip不在范围内 直接抓包加client-ip: 127.0.0.1 即可得到flag web2 <?php include 'here.php';    $key = 'kela ...

随机推荐

  1. 2019牛客多校第八场A All-one Matrices 悬线法,单调栈待补

    All-one Matrices 题意 对于一个n,m的01矩阵,问有多少个极大矩阵. 分析 对于悬线法来说,其过程就是枚举极大矩阵的过程,那如何计数呢?对于一个点来说,若其左右边界包含了上一个点的悬 ...

  2. Attention machenism

    from attention mechanism Attention is one component of a network’s architecture, and is in charge of ...

  3. Python标准库之时间模块time与datatime模块详解

    时间模块time与datatime 时间表示方式: 时间戳 格式化时间字符串 元组 时间戳格式: time.time()#输出1581664531.749063 元组格式: time.localtim ...

  4. web前端技术阅读

    2015年 <响应式web设计>--响应式布局,渐进增强,优雅降级 <javascript高级程序设计>--js基础 2016年 <javascript语言精粹>- ...

  5. redis的linux安装

    1.下载安装包 [root@localhost opt]# yum install wget [root@localhost opt]# wget http://download.redis.io/r ...

  6. AE接口编程

    [转]原文链接:https://malagis.com/arcgis-engine-10-develop-handbook-2-1.html 使用 ArcGIS Engine,也就意味着使用里面的接口 ...

  7. python面试的100题(14)

    32.请写出一个函数满足以下条件 该函数的输入是一个仅包含数字的list,输出一个新的list,其中每一个元素要满足以下条件: 1.该元素是偶数 2.该元素在原list中是在偶数的位置(index是偶 ...

  8. 使用Echarts实现折线图的一点总结

    使用Echarts的一点总结 1.安装,我使用得vue cnpm install echarts --save 2.在入口文件main.js中注册,并使用 // 引入折线图 echarts impor ...

  9. AcWing 275. 传纸条

    #include<iostream> using namespace std ; ; *N][N][N]; int w[N][N]; int n,m; int main() { cin&g ...

  10. jQuery添加/删除元素

    jQuery append() 方法 jQuery append() 方法在被选元素的结尾插入内容(仍然该元素的内部). 追加前:<p>这是一个文本段落</p> $(" ...