> 文档中心 > Java高校教材征订系统的设计与实现

Java高校教材征订系统的设计与实现


大家好,最近在网上又找到了一个学习项目,在此写一篇博文记录一下,在java项目的专栏中我会持 续的更新在网上获取到的java学习项目,这个专栏是我的项目收集专栏吧。在博文中我也会陆续的加入项目的演示视频,读者也可以直接通过视频进行观看项目的功能。

本次项目名:Java高校教材征订系统的设计与实现

本次项目编号:054

一、项目展示图片

 

 二、项目主要代码

package dao;import java.io.FileInputStream;import java.io.IOException;import java.io.InputStream;import java.io.PrintWriter;import java.sql.Connection;import java.sql.DriverManager;import java.sql.ResultSet;import java.sql.ResultSetMetaData;import java.sql.SQLException;import java.sql.Statement;import java.util.ArrayList;import java.util.Collection;import java.util.Date;import java.util.Enumeration;import java.util.HashMap;import java.util.Iterator;import java.util.List;import java.util.Map;import java.util.Properties;import javax.servlet.ServletContext;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import util.Info;public class CommDAO{public static String dbname = "";public static String dbtype = "";public static Connection conn = null;public CommDAO(){conn = this.getConn();}  //给字段做加减法 public void jiajian(String tablename,String colname,String id,String num) { HashMap map = this.getmap(id, tablename); String value = map.get(colname).toString(); if(value.equals(""))value="0"; int i = Integer.parseInt(value); int j = Integer.parseInt(num); commOper("update "+tablename+" set "+colname+" = "+(i+j)+" where id="+id); } //该方法返回一个table 用于流动图片public String DynamicImage(String categoryid,int cut,int width,int height){StringBuffer imgStr = new StringBuffer();StringBuffer thePics1 = new StringBuffer();StringBuffer theLinks1 = new StringBuffer();StringBuffer theTexts1 = new StringBuffer();imgStr.append("
\n\n");thePics1.append("var thePics1=\n'");theLinks1.append("var theLinks1='");theTexts1.append("var theTexts1='");List co = this.select("select * from xinwentongzhi where shouyetupian'' and shouyetupian'null' and shouyetupian like '%.jpg' order by id desc",1,6);int i = co.size();int j = 0; for(HashMap b:co){j++; int id = Integer.parseInt(b.get("id").toString()) ;String title = Info.subStr(b.get("biaoti").toString(), 21) ;String url = ""+b.get("shouyetupian");String purl = "gg_detail.jsp?id="+b.get("id");if(j!=i){thePics1.append(url.replaceAll("\n", "")+"|");theLinks1.append(purl+"|");theTexts1.append(title+"|");}if(j==i){thePics1.append(url.replaceAll("\n", ""));theLinks1.append("gg_detail.jsp?id="+b.get("id"));theTexts1.append(title);}} thePics1.append("';");theLinks1.append("';");theTexts1.append("';");imgStr.append(thePics1+"\n");imgStr.append(theLinks1+"\n");imgStr.append(theTexts1+"\n");imgStr.append("\n setPic(thePics1,theLinks1,theTexts1,"+width+","+height+",'picViwer1');");return imgStr.toString();} public HashMap getmap(String id,String table){List list = new ArrayList();try {Statement st = conn.createStatement();//System.out.println("select * from "+table+" where id="+id); ResultSet rs = st.executeQuery("select * from "+table+" where id="+id); ResultSetMetaData rsmd = rs.getMetaData(); while(rs.next()) { HashMap map = new HashMap(); int i = rsmd.getColumnCount(); for(int j=1;j<=i;j++) { if(!rsmd.getColumnName(j).equals("ID")) { String str = rs.getString(j)==null?"": rs.getString(j); if(str.equals("null"))str = ""; map.put(rsmd.getColumnName(j), str); } else map.put("id", rs.getString(j)); } list.add(map); } rs.close(); st.close();} catch (SQLException e) {// TODO Auto-generated catch blocke.printStackTrace();}return list.get(0);}public HashMap getmaps(String nzd,String zdz,String table){List list = new ArrayList();try {Statement st = conn.createStatement();//System.out.println("select * from "+table+" where "+nzd+"='"+zdz+"'"); ResultSet rs = st.executeQuery("select * from "+table+" where "+nzd+"='"+zdz+"'"); ResultSetMetaData rsmd = rs.getMetaData(); while(rs.next()) { HashMap map = new HashMap(); int i = rsmd.getColumnCount(); for(int j=1;j<=i;j++) { if(!rsmd.getColumnName(j).equals("ID")) { String str = rs.getString(j)==null?"": rs.getString(j); if(str.equals("null"))str = ""; map.put(rsmd.getColumnName(j), str); } else map.put("id", rs.getString(j)); } list.add(map); } rs.close(); st.close();} catch (SQLException e) {// TODO Auto-generated catch blocke.printStackTrace();}return list.get(0);} public String insert(HttpServletRequest request,HttpServletResponse response, String tablename,HashMap extmap,boolean alert,boolean reflush,String tzurl){extmap.put("addtime", Info.getDateStr());if(request.getParameter("f")!=null){HashMap typemap = new HashMap();ArrayList collist = new ArrayList();String sql = "insert into "+tablename+"("; Connection conn = this.getConn();try {Statement st = conn.createStatement(); ResultSet rs = st.executeQuery("select * from "+tablename); ResultSetMetaData rsmd = rs.getMetaData(); int i = rsmd.getColumnCount(); for(int j=1;j-1) { String[] values = request.getParameterValues(str); String value=""; for(String vstr:values) { if(vstr==null)vstr=""; if(vstr.equals("null"))vstr=""; if(vstr.trim().equals(""))continue; if(request.getParameter(vstr)!=null&&!"".equals(request.getParameter(vstr))&&request.getParameter("dk-"+str+"-value")!=null) { String dkv = request.getParameter(vstr); String dknamevalue = request.getParameter("dk-"+str+"-value"); vstr+=" - "+dknamevalue+":"+dkv; } value+=vstr+" ~ "; } if(value==null)value=""; if(value.equals("null"))value=""; if(value.length()>0)value=value.substring(0,value.length()-3); if(typemap.get(str+"---").equals("int")) { sql+=(value.equals("")?-10:value)+","; }else{ sql+="'"+(value.equals("null")?"":value)+"',"; } }else{ if(typemap.get(str+"---").equals("int")) { sql+=(extmap.get(str)==null?"":extmap.get(str))+","; }else{ sql+="'"+(extmap.get(str)==null?"":extmap.get(str))+"',"; } } } sql=sql.substring(0,sql.length()-1)+")"; System.out.println(sql); this.commOper(sql); st.close(); } catch (SQLException e) {e.printStackTrace();}String str = "";if(!reflush) str += " \n"; str +="\n";if(alert){str+="alert('操作成功');\n";}if(tzurl.equals("")){if(reflush){str+="parent.location=parent.location;\n";}else{str+="window.location=String(window.location).replace(new RegExp('f=f', 'g'), '');";}}else{str+="location.href='"+tzurl+"';\n";}str+="";PrintWriter wrt = null;try {wrt = response.getWriter();} catch (IOException e) {// TODO Auto-generated catch blocke.printStackTrace();}wrt.write(str);}return "";}public void delete(HttpServletRequest request,String tablename){int i = 0;try {String did = request.getParameter("did");if(did==null)did = request.getParameter("scid");if(did!=null){if(did.length()>0){Statement st = conn.createStatement();System.out.println("delete from "+tablename+" where id="+did); st.execute("delete from "+tablename+" where id="+did); st.close();}} } catch (SQLException e) {// TODO Auto-generated catch blocke.printStackTrace();} }public String getCols(String table){ String str = "";Connection conn = this.getConn();try {Statement st = conn.createStatement(); ResultSet rs = st.executeQuery("select * from "+table); ResultSetMetaData rsmd = rs.getMetaData(); int i = rsmd.getColumnCount(); for(int j=2;j<=i;j++) { str+=rsmd.getColumnName(j)+","; } }catch (Exception e) {e.printStackTrace();}str = str.substring(0,str.length()-1); return str;}public String update(HttpServletRequest request,HttpServletResponse response, String tablename,HashMap extmap,boolean alert,boolean reflush,String tzurl){if(request.getParameter("f")!=null){Enumeration enumeration = request.getParameterNames();String names = ",";while(enumeration.hasMoreElements()){names += enumeration.nextElement().toString()+",";}HashMap typemap = new HashMap();ArrayList collist = new ArrayList();String sql = "update "+tablename+" set ";Connection conn = this.getConn();try {Statement st = conn.createStatement(); ResultSet rs = st.executeQuery("select * from "+tablename); ResultSetMetaData rsmd = rs.getMetaData(); int i = rsmd.getColumnCount(); System.out.println(i); for(int j=1;j-1) { String[] values = request.getParameterValues(rsmd.getColumnName(j)); String value=""; for(String vstr:values) { if(vstr==null)vstr=""; if(vstr.equals("null"))vstr=""; if(vstr.trim().equals(""))continue; if(request.getParameter(vstr)!=null&&!"".equals(request.getParameter(vstr))&&request.getParameter("dk-"+rsmd.getColumnName(j)+"-value")!=null) { String dkv = request.getParameter(vstr); String dknamevalue = request.getParameter("dk-"+rsmd.getColumnName(j)+"-value"); vstr+=" - "+dknamevalue+":"+dkv; System.out.println(vstr); } //if(vstr.length()0)value=value.substring(0,value.length()-3); if(rsmd.getColumnTypeName(j).equals("int")) { sql+=rsmd.getColumnName(j)+"="+value+","; }else{ sql+=rsmd.getColumnName(j)+"='"+value+"',"; } }else{ if(extmap.get(rsmd.getColumnName(j))!=null) { if(rsmd.getColumnTypeName(j).equals("int")) { sql+=rsmd.getColumnName(j)+"="+extmap.get(rsmd.getColumnName(j))+","; }else{ sql+=rsmd.getColumnName(j)+"='"+extmap.get(rsmd.getColumnName(j))+"',"; } } } } sql = sql.substring(0,sql.length()-1); sql+=" where id="+request.getParameter("id");System.out.println(sql); Statement st1 = conn.createStatement(); st1.execute(sql); st1.close(); rs.close(); st.close(); } catch (SQLException e) {e.printStackTrace();}String str = "";if(!reflush) str += "\n" ; str +="\n";if(alert){str+="alert('操作成功');\n";}if(tzurl.equals("")){if(reflush){str+="parent.location=parent.location;\n";}else{str+="window.location=String(window.location).replace(new RegExp('f=f', 'g'), '');";}}else{str+="location.href='"+tzurl+"';\n";} str+="\n";PrintWriter wrt = null;try {//request.getwrt = response.getWriter();} catch (IOException e) {// TODO Auto-generated catch blocke.printStackTrace();}wrt.write(str);} return "";}public Connection getConn(){ try { if(conn==null||conn.isClosed()){ Class.forName("com.mysql.jdbc.Driver"); conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/jspmgxjczdxthsg2856CCmysql","root","root"); //Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver"); //conn = DriverManager.getConnection("jdbc:sqlserver://localhost:1433;databaseName=jspmgxjczdxthsg2856CC","sa","sa123456"); // Class.forName("net.sourceforge.jtds.jdbc.Driver"); // conn = DriverManager.getConnection("jdbc:jtds:sqlserver://127.0.0.1:1433;databaseName=jspmgxjczdxthsg2856CC","sa","sa123456"); }} catch(Exception e) { e.printStackTrace(); } return conn;}public int getInt(String sql){int i = 0;try {Statement st = conn.createStatement();ResultSet rs = st.executeQuery(sql);if(rs.next()){i = rs.getInt(1);} st.close();} catch (SQLException e) {// TODO Auto-generated catch blocke.printStackTrace();}return i;}public double getDouble(String sql){double i = 0;try {Statement st = conn.createStatement();ResultSet rs = st.executeQuery(sql);if(rs.next()){i = rs.getDouble(1);} st.close();} catch (SQLException e) {// TODO Auto-generated catch blocke.printStackTrace();}return i;}public void commOper(String sql){System.out.println(sql);try {Statement st = conn.createStatement(); st.execute(sql); st.close();} catch (SQLException e) {// TODO Auto-generated catch blocke.printStackTrace();}}public void commOperSqls(ArrayList sql){try {conn.setAutoCommit(false);for(int i=0;i<sql.size();i++){Statement st = conn.createStatement();System.out.println(sql.get(i)); st.execute(sql.get(i)); st.close();}conn.commit();} catch (SQLException e) {try {conn.rollback();} catch (SQLException e1) {e1.printStackTrace();}e.printStackTrace();}finally{try {conn.setAutoCommit(true);} catch (SQLException e) {e.printStackTrace();}}}public List select(String sql){ System.out.println(sql);List list = new ArrayList();try {Statement st = conn.createStatement(); ResultSet rs = st.executeQuery(sql); ResultSetMetaData rsmd = rs.getMetaData(); while(rs.next()) { HashMap map = new HashMap(); int i = rsmd.getColumnCount(); for(int j=1;j<=i;j++) { if(!rsmd.getColumnName(j).equals("ID")) { String str = rs.getString(j)==null?"": rs.getString(j); if(str.equals("null"))str = ""; map.put(rsmd.getColumnName(j), str); } else map.put("id", rs.getString(j)); } list.add(map); } rs.close(); st.close();} catch (SQLException e) {// TODO Auto-generated catch blockif(sql.equals("show tables"))list = select("select table_name from INFORMATION_SCHEMA.tables");elsee.printStackTrace();}return list;}public List selectforlist(String sql){List list = new ArrayList();try {Statement st = conn.createStatement(); ResultSet rs = st.executeQuery(sql); ResultSetMetaData rsmd = rs.getMetaData(); while(rs.next()) { List list2 = new ArrayList(); int i = rsmd.getColumnCount(); for(int j=1;j<=i;j++) { if(!rsmd.getColumnName(j).equals("ID")) { String str = rs.getString(j)==null?"": rs.getString(j); if(str.equals("null"))str = ""; list2.add( str); } else list2.add(rs.getString(j)); } list.add(list2); } rs.close(); st.close();} catch (SQLException e) {// TODO Auto-generated catch blocke.printStackTrace();}return list;}public void close(){ }/** * 执行一条查询sql,以 List 的形式返回查询的记录,记录条数,和从第几条开始,由参数决定,主要用于翻页 * pageno 页码 rowsize 每页的条数 */public List select(String sql, int pageno, int rowsize) {List list=new ArrayList();List mlist=new ArrayList();try{list=this.select(sql);int min = (pageno-1)*rowsize;int max = pageno*rowsize;for(int i=0;i<list.size();i++){if(!(i(max-1))){mlist.add(list.get(i));}}}catch(RuntimeException re){re.printStackTrace();throw re;}return mlist;}public static void main(String[] args) { }}

 

package control;import java.io.BufferedInputStream;import java.io.BufferedOutputStream;import java.io.File;import java.io.FileInputStream;import java.io.IOException;import java.io.InputStream;import java.io.OutputStream;import java.io.PrintWriter;import java.io.UnsupportedEncodingException;import java.net.URLEncoder;import java.util.ArrayList;import java.util.HashMap;import java.util.List;import javax.servlet.ServletException;import javax.servlet.http.HttpServlet;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import jxl.Cell;import jxl.Sheet;import jxl.Workbook;import org.apache.commons.fileupload.FileItem;import org.apache.commons.fileupload.FileUpload;import org.apache.commons.fileupload.RequestContext;import org.apache.commons.fileupload.disk.DiskFileItemFactory;import org.apache.commons.fileupload.servlet.ServletFileUpload;import org.apache.commons.fileupload.servlet.ServletRequestContext;import util.Info;import dao.CommDAO;public class MainCtrl extends HttpServlet {public MainCtrl() {super();}public void destroy() {super.destroy(); // Just puts "destroy" string in log// Put your code here}public void doGet(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException {this.doPost(request, response);}public void go(String url,HttpServletRequest request, HttpServletResponse response){try {request.getRequestDispatcher(url).forward(request, response);} catch (ServletException e) {e.printStackTrace();} catch (IOException e) {e.printStackTrace();}}public void gor(String url,HttpServletRequest request, HttpServletResponse response){try {response.sendRedirect(url);} catch (IOException e) {// TODO Auto-generated catch blocke.printStackTrace();}}public void doPost(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException { response.setContentType("text/html");PrintWriter out = response.getWriter();String ac = request.getParameter("ac");if(ac==null)ac="";CommDAO dao = new CommDAO();String date = Info.getDateStr();String today = date.substring(0,10);String tomonth = date.substring(0,7); if(ac.equals("login")){String username = request.getParameter("username");String password = request.getParameter("pwd1");String utype = request.getParameter("cx");String pagerandom = request.getParameter("pagerandom")==null?"":request.getParameter("pagerandom");String random = (String)request.getSession().getAttribute("random");if(!pagerandom.equals(random)&&request.getParameter("a")!=null){request.setAttribute("random", "");go("/index.jsp", request, response);}else{String sql1="";if (utype.equals("管理员")){sql1 = "select * from allusers where username='"+username+"' and pwd='"+password+"'"; }if(utype.equals("院系管理员")){sql1 = "select * from yuanxiguanliyuan where gonghao='"+username+"' and mima='"+password+"' ";}List userlist1 = dao.select(sql1);if(userlist1.size()==1){request.getSession(). setAttribute("username", username);  if (utype.equals("管理员")){request.getSession(). setAttribute("cx",  userlist1.get(0).get("cx"));  }else{request.getSession(). setAttribute("cx", utype);  }gor("index.jsp", request, response);}else{request.setAttribute("error", "");go("/index.jsp", request, response);}}}if(ac.equals("adminlogin")){String username = request.getParameter("username");String password = request.getParameter("pwd");String utype = request.getParameter("cx");String pagerandom = request.getParameter("pagerandom")==null?"":request.getParameter("pagerandom");String random = (String)request.getSession().getAttribute("random");if(!pagerandom.equals(random)&&request.getParameter("a")!=null){request.setAttribute("random", "");go("/login.jsp", request, response);}else{String sql1 = "";if (utype.equals("管理员")){sql1 = "select * from allusers where username='"+username+"' and pwd='"+password+"'"; }if(utype.equals("院系管理员")){sql1 = "select * from yuanxiguanliyuan where gonghao='"+username+"' and mima='"+password+"' ";}List userlist1 = dao.select(sql1);if(userlist1.size()==1){request.getSession(). setAttribute("username", username);  if (utype.equals("管理员")){request.getSession(). setAttribute("cx",  userlist1.get(0).get("cx"));  }else{request.getSession(). setAttribute("cx", utype);  }gor("main.jsp", request, response);}else{request.setAttribute("error", "");go("/login.jsp", request, response);}}}//修改密码if(ac.equals("uppass")){String olduserpass = request.getParameter("ymm");String userpass = request.getParameter("xmm1");String copyuserpass = request.getParameter("xmm2");   HashMap m = dao.getmaps("yonghuming",(String)request.getSession().getAttribute("username"), "yonghuzhuce");if(!(((String)m.get("mima")).equals(olduserpass))){request.setAttribute("error", "");go("mod2.jsp", request, response);}else{//String id = (String)user.get("id");String sql = "update yonghuzhuce set mima='"+userpass+"' where yonghuming='"+(String)request.getSession().getAttribute("username")+"'";dao.commOper(sql);request.setAttribute("suc", "");go("mod2.jsp", request, response);}}  //修改密码if(ac.equals("adminuppass")){String olduserpass = request.getParameter("ymm");String userpass = request.getParameter("xmm1");String copyuserpass = request.getParameter("xmm2");   //println(Info.getUser(request).get("id").toString());HashMap m = dao.getmaps("username",(String)request.getSession().getAttribute("username"), "allusers");if(!(((String)m.get("pwd")).equals(olduserpass))){request.setAttribute("error", "");go("mod.jsp", request, response);}else{//String id = (String)user.get("id");String sql = "update allusers set pwd='"+userpass+"' where username='"+(String)request.getSession().getAttribute("username")+"'";dao.commOper(sql);request.setAttribute("suc", "");go("mod.jsp", request, response);}} if(ac.equals("uploaddoc")){try {String filename="";request.setCharacterEncoding("gb2312");RequestContext  requestContext = new ServletRequestContext(request);if(FileUpload.isMultipartContent(requestContext)){   DiskFileItemFactory factory = new DiskFileItemFactory();   factory.setRepository(new File(request.getRealPath("/upfile/")+"/"));   ServletFileUpload upload = new ServletFileUpload(factory);   upload.setSizeMax(100*1024*1024);   List items = new ArrayList();  items = upload.parseRequest(request);  FileItem fileItem = (FileItem) items.get(0);   if(fileItem.getName()!=null && fileItem.getSize()!=0)    {    if(fileItem.getName()!=null && fileItem.getSize()!=0){      File fullFile = new File(fileItem.getName());      filename = Info.generalFileName(fullFile.getName());      File newFile = new File(request.getRealPath("/upfile/")+"/" + filename);      try {fileItem.write(newFile);      } catch (Exception e) {e.printStackTrace();      }     }else{     }    }}go("/js/uploaddoc.jsp?docname="+filename, request, response);} catch (Exception e1) {e1.printStackTrace();    }}if(ac.equals("uploaddoc2")){try {String filename="";request.setCharacterEncoding("gb2312");RequestContext  requestContext = new ServletRequestContext(request);if(FileUpload.isMultipartContent(requestContext)){   DiskFileItemFactory factory = new DiskFileItemFactory();   factory.setRepository(new File(request.getRealPath("/upfile/")+"/"));   ServletFileUpload upload = new ServletFileUpload(factory);   upload.setSizeMax(100*1024*1024);   List items = new ArrayList();  items = upload.parseRequest(request);  FileItem fileItem = (FileItem) items.get(0);   if(fileItem.getName()!=null && fileItem.getSize()!=0)    {    if(fileItem.getName()!=null && fileItem.getSize()!=0){      File fullFile = new File(fileItem.getName());      filename = Info.generalFileName(fullFile.getName());      File newFile = new File(request.getRealPath("/upfile/")+"/" + filename);      try {fileItem.write(newFile);      } catch (Exception e) {e.printStackTrace();      }     }else{     }    }}go("/js/uploaddoc2.jsp?docname="+filename, request, response);} catch (Exception e1) {e1.printStackTrace();    }}if(ac.equals("uploaddoc3")){try {String filename="";request.setCharacterEncoding("gb2312");RequestContext  requestContext = new ServletRequestContext(request);if(FileUpload.isMultipartContent(requestContext)){   DiskFileItemFactory factory = new DiskFileItemFactory();   factory.setRepository(new File(request.getRealPath("/upfile/")+"/"));   ServletFileUpload upload = new ServletFileUpload(factory);   upload.setSizeMax(100*1024*1024);   List items = new ArrayList();  items = upload.parseRequest(request);  FileItem fileItem = (FileItem) items.get(0);   if(fileItem.getName()!=null && fileItem.getSize()!=0)    {    if(fileItem.getName()!=null && fileItem.getSize()!=0){      File fullFile = new File(fileItem.getName());      filename = Info.generalFileName(fullFile.getName());      File newFile = new File(request.getRealPath("/upfile/")+"/" + filename);      try {fileItem.write(newFile);      } catch (Exception e) {e.printStackTrace();      }     }else{     }    }}go("/js/uploaddoc3.jsp?docname="+filename, request, response);} catch (Exception e1) {e1.printStackTrace();    }}//导excelif(ac.equals("importexcel")){String page = request.getParameter("page");String whzdstr = request.getParameter("whzdstr");String tablename = request.getParameter("tablename");try {String filename="";request.setCharacterEncoding("gb2312");RequestContext  requestContext = new ServletRequestContext(request);if(FileUpload.isMultipartContent(requestContext)){   DiskFileItemFactory factory = new DiskFileItemFactory();   factory.setRepository(new File(request.getRealPath("/upfile/")+"/"));   ServletFileUpload upload = new ServletFileUpload(factory);   upload.setSizeMax(100*1024*1024);   List items = new ArrayList();  items = upload.parseRequest(request);  FileItem fileItem = (FileItem) items.get(0);   if(fileItem.getName()!=null && fileItem.getSize()!=0)    {    if(fileItem.getName()!=null && fileItem.getSize()!=0){      File fullFile = new File(fileItem.getName());      filename = Info.generalFileName(fullFile.getName());      File newFile = new File(request.getRealPath("/upfile/")+"/" + filename);      try {fileItem.write(newFile);      } catch (Exception e) {e.printStackTrace();      }     }else{     }    }if(filename.indexOf(".xls")>-1){Workbook workbook;try {workbook = Workbook.getWorkbook(new File(request.getRealPath("/upfile/")+"/"+filename)); //通过Workbook的getSheet方法选择第一个工作簿(从0开始)Sheet sheet = workbook.getSheet(0);  //通过Sheet方法的getCell方法选择位置为C2的单元格(两个参数都从0开始)//int empty = 0;for(int i=1;i<1000;i++){Cell cell = null;try{String isql = "insert into "+tablename+"(";for(String str:whzdstr.split("-")){ isql+=str+",";}isql = isql.substring(0,isql.length()-1);isql+=")values(";int j=0;int empty = 1;for(String str:whzdstr.split("-")){cell = sheet.getCell(j,i); isql+="'"+cell.getContents()+"',";String content = cell.getContents()==null?"":cell.getContents();if(!"".equals(content.trim())){empty = 0;}j++;}if(empty==1)continue;isql = isql.substring(0,isql.length()-1);isql+=")";dao.commOper(isql);}catch (Exception e) {continue;}     }  workbook.close();      } catch (Exception e) {e.printStackTrace();}     }}go("/admin/"+page+"?docname="+filename, request, response);} catch (Exception e1) {e1.printStackTrace();}}  if(ac.equals("uploadimg")){try {String filename="";request.setCharacterEncoding("gb2312");RequestContext  requestContext = new ServletRequestContext(request);if(FileUpload.isMultipartContent(requestContext)){   DiskFileItemFactory factory = new DiskFileItemFactory();   factory.setRepository(new File(request.getRealPath("/upfile/")+"/"));   ServletFileUpload upload = new ServletFileUpload(factory);   upload.setSizeMax(100*1024*1024);   List items = new ArrayList();  items = upload.parseRequest(request);  FileItem fileItem = (FileItem) items.get(0);   if(fileItem.getName()!=null && fileItem.getSize()!=0)    {    if(fileItem.getName()!=null && fileItem.getSize()!=0){      File fullFile = new File(fileItem.getName());      filename = Info.generalFileName(fullFile.getName());      File newFile = new File(request.getRealPath("/upfile/")+"/" + filename);      try {fileItem.write(newFile);      } catch (Exception e) {e.printStackTrace();      }     }else{     }    }}go("/js/uploadimg.jsp?filename="+filename, request, response);} catch (Exception e1) {e1.printStackTrace();    }}if(ac.equals("uploadimg2")){try {String filename="";request.setCharacterEncoding("gb2312");RequestContext  requestContext = new ServletRequestContext(request);if(FileUpload.isMultipartContent(requestContext)){   DiskFileItemFactory factory = new DiskFileItemFactory();   factory.setRepository(new File(request.getRealPath("/upfile/")+"/"));   ServletFileUpload upload = new ServletFileUpload(factory);   upload.setSizeMax(100*1024*1024);   List items = new ArrayList();  items = upload.parseRequest(request);  FileItem fileItem = (FileItem) items.get(0);   if(fileItem.getName()!=null && fileItem.getSize()!=0)    {    if(fileItem.getName()!=null && fileItem.getSize()!=0){      File fullFile = new File(fileItem.getName());      filename = Info.generalFileName(fullFile.getName());      File newFile = new File(request.getRealPath("/upfile/")+"/" + filename);      try {fileItem.write(newFile);      } catch (Exception e) {e.printStackTrace();      }     }else{     }    }}go("/js/uploadimg2.jsp?filename="+filename, request, response);} catch (Exception e1) {e1.printStackTrace();    }}if(ac.equals("uploadimg3")){try {String filename="";request.setCharacterEncoding("gb2312");RequestContext  requestContext = new ServletRequestContext(request);if(FileUpload.isMultipartContent(requestContext)){   DiskFileItemFactory factory = new DiskFileItemFactory();   factory.setRepository(new File(request.getRealPath("/upfile/")+"/"));   ServletFileUpload upload = new ServletFileUpload(factory);   upload.setSizeMax(100*1024*1024);   List items = new ArrayList();  items = upload.parseRequest(request);  FileItem fileItem = (FileItem) items.get(0);   if(fileItem.getName()!=null && fileItem.getSize()!=0)    {    if(fileItem.getName()!=null && fileItem.getSize()!=0){      File fullFile = new File(fileItem.getName());      filename = Info.generalFileName(fullFile.getName());      File newFile = new File(request.getRealPath("/upfile/")+"/" + filename);      try {fileItem.write(newFile);      } catch (Exception e) {e.printStackTrace();      }     }else{     }    }}go("/js/uploadimg3.jsp?filename="+filename, request, response);} catch (Exception e1) {e1.printStackTrace();    }}if(ac.equals("uploadimg4")){try {String filename="";request.setCharacterEncoding("gb2312");RequestContext  requestContext = new ServletRequestContext(request);if(FileUpload.isMultipartContent(requestContext)){   DiskFileItemFactory factory = new DiskFileItemFactory();   factory.setRepository(new File(request.getRealPath("/upfile/")+"/"));   ServletFileUpload upload = new ServletFileUpload(factory);   upload.setSizeMax(100*1024*1024);   List items = new ArrayList();  items = upload.parseRequest(request);  FileItem fileItem = (FileItem) items.get(0);   if(fileItem.getName()!=null && fileItem.getSize()!=0)    {    if(fileItem.getName()!=null && fileItem.getSize()!=0){      File fullFile = new File(fileItem.getName());      filename = Info.generalFileName(fullFile.getName());      File newFile = new File(request.getRealPath("/upfile/")+"/" + filename);      try {fileItem.write(newFile);      } catch (Exception e) {e.printStackTrace();      }     }else{     }    }}go("/js/uploadimg4.jsp?filename="+filename, request, response);} catch (Exception e1) {e1.printStackTrace();    }}if(ac.equals("uploadimg5")){try {String filename="";request.setCharacterEncoding("gb2312");RequestContext  requestContext = new ServletRequestContext(request);if(FileUpload.isMultipartContent(requestContext)){   DiskFileItemFactory factory = new DiskFileItemFactory();   factory.setRepository(new File(request.getRealPath("/upfile/")+"/"));   ServletFileUpload upload = new ServletFileUpload(factory);   upload.setSizeMax(100*1024*1024);   List items = new ArrayList();  items = upload.parseRequest(request);  FileItem fileItem = (FileItem) items.get(0);   if(fileItem.getName()!=null && fileItem.getSize()!=0)    {    if(fileItem.getName()!=null && fileItem.getSize()!=0){      File fullFile = new File(fileItem.getName());      filename = Info.generalFileName(fullFile.getName());      File newFile = new File(request.getRealPath("/upfile/")+"/" + filename);      try {fileItem.write(newFile);      } catch (Exception e) {e.printStackTrace();      }     }else{     }    }}go("/js/uploadimg5.jsp?filename="+filename, request, response);} catch (Exception e1) {e1.printStackTrace();    }}dao.close();out.flush();out.close();}public void init() throws ServletException {// Put your code here}}

三、项目数据库代码

/*Navicat MySQL Data TransferSource Server  : localhost_3306Source Server Version : 50160Source Host    : localhost:3306Source Database: jspmgxjczdxthsg2856ccmysqlTarget Server Type    : MYSQLTarget Server Version : 50160File Encoding  : 65001Date: 2022-03-18 20:51:13*/SET FOREIGN_KEY_CHECKS=0;-- ------------------------------ Table structure for `allusers`-- ----------------------------DROP TABLE IF EXISTS `allusers`;CREATE TABLE `allusers` (  `ID` int(11) NOT NULL AUTO_INCREMENT,  `username` varchar(50) DEFAULT NULL,  `pwd` varchar(50) DEFAULT NULL,  `cx` varchar(50) DEFAULT NULL,  `addtime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,  PRIMARY KEY (`ID`)) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8;-- ------------------------------ Records of allusers-- ----------------------------INSERT INTO `allusers` VALUES ('1', 'hsg', 'hsg', '瓒呯骇绠$悊鍛�', '2022-03-01 01:53:27');-- ------------------------------ Table structure for `kucunxinxi`-- ----------------------------DROP TABLE IF EXISTS `kucunxinxi`;CREATE TABLE `kucunxinxi` (  `ID` int(11) NOT NULL AUTO_INCREMENT,  `shujibianhao` varchar(50) DEFAULT NULL,  `shujimingcheng` varchar(50) DEFAULT NULL,  `chubanriqi` varchar(50) DEFAULT NULL,  `shujijiage` varchar(50) DEFAULT NULL,  `shujizuozhe` varchar(50) DEFAULT NULL,  `chubanshemingcheng` varchar(50) DEFAULT NULL,  `chubanshedizhi` varchar(50) DEFAULT NULL,  `shujikucun` varchar(50) DEFAULT NULL,  `rukushuliang` varchar(50) DEFAULT NULL,  `zongjine` varchar(50) DEFAULT NULL,  `addtime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,  PRIMARY KEY (`ID`)) ENGINE=InnoDB AUTO_INCREMENT=12 DEFAULT CHARSET=utf8;-- ------------------------------ Records of kucunxinxi-- ----------------------------INSERT INTO `kucunxinxi` VALUES ('1', '312895589104', '灏戞湁浜鸿蛋鐨勮矾', '2022-1-31', '69', '绉戞瘮', '娓╁窞鏂板崕鍑虹増绀�', '娉板叴璺�22鍙�', '67', '59', '4071', '2022-03-01 02:11:19');INSERT INTO `kucunxinxi` VALUES ('2', '312855599535', '绠�鐖�', '2022-3-8', '69', '鐜嬫煆寮�', '鏃呮父鍑虹増绀�', '閼拰閿﹀洯2鏍�', '67', '82', '5658', '2022-03-01 02:11:19');INSERT INTO `kucunxinxi` VALUES ('3', '312806508056', '绠�鐖�', '2022-3-20', '54', '闄堣吹鏌�', '榛庢槑鍑虹増绀�', '寤哄叴璺�138鍙�', '67', '97', '5238', '2022-03-01 02:11:19');INSERT INTO `kucunxinxi` VALUES ('4', '312834669782', '瀹夊鍗″垪鐞冲', '2022-1-31', '83', '椹簡鐐�', '鍗椾含鏅开鍑虹増绀�', '榫欑繑璺�11鍙�', '99', '76', '6308', '2022-03-01 02:11:19');INSERT INTO `kucunxinxi` VALUES ('5', '312895589104', '灏戞湁浜鸿蛋鐨勮矾', '2022-1-31', '69', '绉戞瘮', '娓╁窞鏂板崕鍑虹増绀�', '娉板叴璺�22鍙�', '67', '97', '6693', '2022-03-01 02:11:19');INSERT INTO `kucunxinxi` VALUES ('6', '312843292730', '瀹夊緬鐢熺璇�', '2022-3-2', '56', '閮戜簹鏂�', '鍖椾含鏂拌春鍑虹増绀�', '鏂瑰煄涓藉渾11骞�201瀹�', '60', '59', '3304', '2022-03-01 02:11:19');INSERT INTO `kucunxinxi` VALUES ('7', '312815131913', '涓夊浗婕斾箟', '2022-3-17', '88', '璧靛Э鍚�', '娴欐睙娉曟鍑虹増绀�', '涓滃煄璺�99鍙�', '2', '43', '3784', '2022-03-01 02:11:19');INSERT INTO `kucunxinxi` VALUES ('8', '312815131913', '涓夊浗婕斾箟', '2022-3-17', '88', '璧靛Э鍚�', '娴欐睙娉曟鍑虹増绀�', '涓滃煄璺�99鍙�', '2', '50', '4400', '2022-03-01 02:11:19');INSERT INTO `kucunxinxi` VALUES ('9', '312815131913', '涓夊浗婕斾箟', '2022-3-17', '88', '璧靛Э鍚�', '娴欐睙娉曟鍑虹増绀�', '涓滃煄璺�99鍙�', '2', '300', '26400.0', '2022-03-01 02:15:31');INSERT INTO `kucunxinxi` VALUES ('10', '312815131913', '涓夊浗婕斾箟', '2022-3-17', '88', '璧靛Э鍚�', '娴欐睙娉曟鍑虹増绀�', '涓滃煄璺�99鍙�', '500', '99999999999', '8.800000016384E12', '2022-03-01 02:25:23');INSERT INTO `kucunxinxi` VALUES ('11', '312815131913', '涓夊浗婕斾箟', '2022-3-17', '88', '璧靛Э鍚�', '娴欐睙娉曟鍑虹増绀�', '涓滃煄璺�99鍙�', '100000000499', '300', '26400.0', '2022-03-01 02:25:32');-- ------------------------------ Table structure for `shujidinggou`-- ----------------------------DROP TABLE IF EXISTS `shujidinggou`;CREATE TABLE `shujidinggou` (  `ID` int(11) NOT NULL AUTO_INCREMENT,  `shujibianhao` varchar(50) DEFAULT NULL,  `shujimingcheng` varchar(50) DEFAULT NULL,  `chubanriqi` varchar(50) DEFAULT NULL,  `shujijiage` varchar(50) DEFAULT NULL,  `shujizuozhe` varchar(50) DEFAULT NULL,  `chubenshemingcheng` varchar(50) DEFAULT NULL,  `shujikucun` varchar(50) DEFAULT NULL,  `shenqingshuliang` varchar(50) DEFAULT NULL,  `zongjine` varchar(50) DEFAULT NULL,  `shenqingren` varchar(50) DEFAULT NULL,  `issh` varchar(2) DEFAULT NULL,  `addtime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,  PRIMARY KEY (`ID`)) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8;-- ------------------------------ Records of shujidinggou-- ----------------------------INSERT INTO `shujidinggou` VALUES ('1', '312815131913', '涓夊浗婕斾箟', '2022-3-17', '88', '璧靛Э鍚�', '', '23', '1', '88.0', '001', '鏄�', '2022-03-01 02:16:51');INSERT INTO `shujidinggou` VALUES ('2', '312815131913', '涓夊浗婕斾箟', '2022-3-17', '88', '璧靛Э鍚�', '', '22', '10', '880.0', '001', '鏄�', '2022-03-01 02:17:57');INSERT INTO `shujidinggou` VALUES ('3', '312815131913', '涓夊浗婕斾箟', '2022-3-17', '88', '璧靛Э鍚�', '', '12', '10', '880.0', '001', '鏄�', '2022-03-01 02:24:45');-- ------------------------------ Table structure for `shujifafang`-- ----------------------------DROP TABLE IF EXISTS `shujifafang`;CREATE TABLE `shujifafang` (  `ID` int(11) NOT NULL AUTO_INCREMENT,  `shujibianhao` varchar(50) DEFAULT NULL,  `shujimingcheng` varchar(50) DEFAULT NULL,  `shujijiage` varchar(50) DEFAULT NULL,  `shujizuozhe` varchar(50) DEFAULT NULL,  `chubanshemingcheng` varchar(50) DEFAULT NULL,  `shujikucun` varchar(50) DEFAULT NULL,  `shenqingshuliang` varchar(50) DEFAULT NULL,  `zongjine` varchar(50) DEFAULT NULL,  `shenqingren` varchar(50) DEFAULT NULL,  `fafangshijian` varchar(50) DEFAULT NULL,  `addtime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,  PRIMARY KEY (`ID`)) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8;-- ------------------------------ Records of shujifafang-- ----------------------------INSERT INTO `shujifafang` VALUES ('1', '312815131913', '涓夊浗婕斾箟', '88', '璧靛Э鍚�', '', '23', '1', '88.0', '001', '2022-03-01', '2022-03-01 02:17:12');INSERT INTO `shujifafang` VALUES ('2', '312815131913', '涓夊浗婕斾箟', '88', '璧靛Э鍚�', '', '12', '10', '880.0', '001', '2022-03-01', '2022-03-01 02:25:42');-- ------------------------------ Table structure for `shujixinxi`-- ----------------------------DROP TABLE IF EXISTS `shujixinxi`;CREATE TABLE `shujixinxi` (  `ID` int(11) NOT NULL AUTO_INCREMENT,  `shujibianhao` varchar(50) DEFAULT NULL,  `shujimingcheng` varchar(50) DEFAULT NULL,  `chubanriqi` varchar(50) DEFAULT NULL,  `shujijiage` varchar(50) DEFAULT NULL,  `shujizuozhe` varchar(50) DEFAULT NULL,  `chubanshemingcheng` varchar(50) DEFAULT NULL,  `chubanshedizhi` varchar(255) DEFAULT NULL,  `shujikucun` varchar(50) DEFAULT NULL,  `shujitupian` varchar(50) DEFAULT NULL,  `addtime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,  PRIMARY KEY (`ID`)) ENGINE=InnoDB AUTO_INCREMENT=9 DEFAULT CHARSET=utf8;-- ------------------------------ Records of shujixinxi-- ----------------------------INSERT INTO `shujixinxi` VALUES ('1', '312834669782', '瀹夊鍗″垪鐞冲', '2022-1-31', '83', '椹簡鐐�', '鍗椾含鏅开鍑虹増绀�', '榫欑繑璺�11鍙�', '99', 'upload/nopic6.jpg', '2022-03-01 02:09:37');INSERT INTO `shujixinxi` VALUES ('2', '312855599535', '绠�鐖�', '2022-3-8', '69', '鐜嬫煆寮�', '鏃呮父鍑虹増绀�', '閼拰閿﹀洯2鏍�', '67', 'upload/nopic2.jpg', '2022-03-01 02:09:37');INSERT INTO `shujixinxi` VALUES ('3', '312893202161', '閲戠摱姊�', '2022-3-20', '88', '鍐瓙鏉�', '涓浗鏃ユ姤鍑虹増绀�', '涓婃睙灏忓尯2骞�', '67', 'upload/nopic8.jpg', '2022-03-01 02:09:37');INSERT INTO `shujixinxi` VALUES ('4', '312854222592', '鑺遍鏂囬泦', '2022-1-31', '83', '楣挎櫁', '涓婃捣鏅氭姤鍑虹増绀�', '娌虫花涓滆矾139鍙�', '23', 'upload/nopic1.jpg', '2022-03-01 02:09:37');INSERT INTO `shujixinxi` VALUES ('5', '312843292730', '瀹夊緬鐢熺璇�', '2022-3-2', '56', '閮戜簹鏂�', '鍖椾含鏂拌春鍑虹増绀�', '鏂瑰煄涓藉渾11骞�201瀹�', '60', 'upload/nopic7.jpg', '2022-03-01 02:09:37');INSERT INTO `shujixinxi` VALUES ('6', '312806508056', '绠�鐖�', '2022-3-20', '54', '闄堣吹鏌�', '榛庢槑鍑虹増绀�', '寤哄叴璺�138鍙�', '67', 'upload/nopic4.jpg', '2022-03-01 02:09:37');INSERT INTO `shujixinxi` VALUES ('7', '312895589104', '灏戞湁浜鸿蛋鐨勮矾', '2022-1-31', '69', '绉戞瘮', '娓╁窞鏂板崕鍑虹増绀�', '娉板叴璺�22鍙�', '67', 'upload/nopic3.jpg', '2022-03-01 02:09:37');INSERT INTO `shujixinxi` VALUES ('8', '312815131913', '涓夊浗婕斾箟', '2022-3-17', '88', '璧靛Э鍚�', '娴欐睙娉曟鍑虹増绀�', '涓滃煄璺�99鍙�', '100000000499', 'upload/nopic5.jpg', '2022-03-01 02:09:37');-- ------------------------------ Table structure for `yuanxiguanliyuan`-- ----------------------------DROP TABLE IF EXISTS `yuanxiguanliyuan`;CREATE TABLE `yuanxiguanliyuan` (  `ID` int(11) NOT NULL AUTO_INCREMENT,  `gonghao` varchar(50) DEFAULT NULL,  `mima` varchar(50) DEFAULT NULL,  `xingming` varchar(50) DEFAULT NULL,  `xingbie` varchar(50) DEFAULT NULL,  `shenfenzheng` varchar(50) DEFAULT NULL,  `shouji` varchar(50) DEFAULT NULL,  `zhaopian` varchar(50) DEFAULT NULL,  `addtime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,  PRIMARY KEY (`ID`)) ENGINE=InnoDB AUTO_INCREMENT=9 DEFAULT CHARSET=utf8;-- ------------------------------ Records of yuanxiguanliyuan-- ----------------------------INSERT INTO `yuanxiguanliyuan` VALUES ('1', '016', '001', '鐜嬩笌棣�', '鐢�', '330327198811020456', '13025896548', 'upload/yuanxiguanliyuan3.jpg', '2022-03-01 01:56:33');INSERT INTO `yuanxiguanliyuan` VALUES ('2', '018', '001', '榛勮闃�', '濂�', '330327198708070789', '17505772420', 'upload/yuanxiguanliyuan4.jpg', '2022-03-01 01:56:33');INSERT INTO `yuanxiguanliyuan` VALUES ('3', '023', '001', '閮椤�', '濂�', '330327199005060003', '13748589658', 'upload/yuanxiguanliyuan1.jpg', '2022-03-01 01:56:33');INSERT INTO `yuanxiguanliyuan` VALUES ('4', '005', '001', '娓╁畻杈�', '濂�', '330327198805060222', '13623256544', 'upload/yuanxiguanliyuan8.jpg', '2022-03-01 01:56:33');INSERT INTO `yuanxiguanliyuan` VALUES ('5', '007', '001', '浼嶅厗鏂�', '鐢�', '330327198406150488', '13910215489', 'upload/yuanxiguanliyuan6.jpg', '2022-03-01 01:56:33');INSERT INTO `yuanxiguanliyuan` VALUES ('6', '012', '001', '鏉ㄩ', '鐢�', '330327198615482633', '13186835580', 'upload/yuanxiguanliyuan2.jpg', '2022-03-01 01:56:33');INSERT INTO `yuanxiguanliyuan` VALUES ('7', '009', '001', '浣欏皯搴�', '濂�', '33032719900723568X', '13184865998', 'upload/yuanxiguanliyuan5.jpg', '2022-03-01 01:56:33');INSERT INTO `yuanxiguanliyuan` VALUES ('8', '001', '001', '濮氭槑', '濂�', '330327199010142546', '13769548711', 'upload/yuanxiguanliyuan7.jpg', '2022-03-01 01:56:33');

四、项目演示视频

观看地址:

https://www.bilibili.com/video/bv1g94y1S7Ep