基于javaweb+mysql的jsp+servlet校园自行车租赁管理系统(java+jsp+javascript+servlet+mysql)
私信源码获取及调试交流
运行环境
Java≥8、MySQL≥5.7、Tomcat≥8
开发工具
eclipse/idea/myeclipse/sts等均可配置运行
适用
课程设计,大作业,毕业设计,项目练习,学习演示等
功能说明
基于javaweb的JSP+Servlet校园自行车租赁管理系统(java+jsp+javascript+servlet+mysql)
项目介绍
本项目分为前后台,包含管理员、站点管理员、用户三种角色;
管理员角色包含以下功能: 管理员登录,管理员管理,车辆类型管理,租赁站点管理,站点管理员管理,自行车信息管理,校园新闻管理,自行车租用统计,友情链接留言系统公告管理等功能。
站点管理员角色包含以下功能: 站点管理员登录,个人资料密码管理,充值管理,租赁归还记录管理,自行车管理,充值记录查询等功能。 用户角色包含以下功能:用户首页,在线留言,用户注册登录,自行车展示,租用自行车,校园新闻查看,租赁记录管理,归还记录管理等功能。
环境需要
1.运行环境:最好是java jdk 1.8,我们在这个平台上运行的。其他版本理论上也可以。 2.IDE环境:IDEA,Eclipse,Myeclipse都可以。推荐IDEA; 3.tomcat环境:Tomcat 7.x,8.x,9.x版本均可 4.硬件环境:windows 7/8/10 1G内存以上;或者 Mac OS; 5.数据库:MySql 5.7版本; 6.是否Maven项目:否;
技术栈
JSP+CSS+JavaScript+Servlet+mysql
使用说明
- 使用Navicat或者其它工具,在mysql中创建对应名称的数据库,并导入项目的sql文件; 2. 使用IDEA/Eclipse/MyEclipse导入项目,Eclipse/MyEclipse导入时,若为maven项目请选择maven; 若为maven项目,导入成功后请执行maven clean;maven install命令,然后运行; 3. 将项目中CommDAO.java配置文件中的第472行数据库配置改为自己的配置; 4. 运行项目,在浏览器中输入localhost:8080/xxx 登录
*/
protected PageManager(String path, int pageSize, HttpServletRequest request) {
// 任意一个dao都行
this.currentPage = 1;
this.pageNumber = 1;
this.count = 0;
this.pageSize = pageSize <= 0 ? DEFAULTPAGESIZE : pageSize;
this.request = request;
this.path = path;
request.setAttribute("page", this);
try {
this.currentPage = Integer.parseInt(request
.getParameter("currentPage")) <= 0 ? 1 : Integer
.parseInt(request.getParameter("currentPage"));
} catch (Exception e) {
try {
this.currentPage = Integer.parseInt((String) request
.getSession().getAttribute("currentPage"));
} catch (Exception e1) {
this.currentPage = 1;
}
}
}
/**
*
* @param 下一页的分页链接
* @param 一页最大记录数
* @param 当前HttpServletRequest对象
* @param 数据库操作对象
*/
public static PageManager getPage(String path, int pageSize,
HttpServletRequest request) {
return new PageManager(path, pageSize, request);
try {
conn.setAutoCommit(true);
} catch (SQLException e) {
e.printStackTrace();
}
}
}
public List<HashMap> select(String sql)
{
System.out.println(sql);
List<HashMap> 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 block
if(sql.equals("show tables"))
list = select("select table_name from INFORMATION_SCHEMA.tables");
else
e.printStackTrace();
}
return list;
}
WritableWorkbook wwb = null;
String cols = "";
for(String str:prosstr.split("@"))
{
cols+=str.split("-")[0]+",";
}
cols = cols.substring(0,cols.length()-1);
String where = request.getAttribute("where")==null?"":request.getAttribute("where").toString();
List<List> mlist = new CommDAO().selectforlist("select "+cols+" from "+fileName+" "+where+" order by id desc");
fileName = request.getRealPath("/")+"/upfile/"+Info.generalFileName("a.xls");
String[] pros = prosstr.split("@");
try {
//首先要使用Workbook类的工厂方法创建一个可写入的工作薄(Workbook)对象
wwb = Workbook.createWorkbook(new File(fileName));
} catch (IOException e) {
e.printStackTrace();
}
if(wwb!=null){
//创建一个可写入的工作表
//Workbook的createSheet方法有两个参数,第一个是工作表的名称,第二个是工作表在工作薄中的位置
WritableSheet ws = wwb.createSheet("sheet1", 0);
ws.setColumnView(0,20);
ws.setColumnView(1,20);
ws.setColumnView(2,20);
ws.setColumnView(3,20);
ws.setColumnView(4,20);
ws.setColumnView(5,20);
try {
for(int i=0;i<pros.length;i++)
{
Label label1 = new Label(i, 0,"");
label1.setString(pros[i]);
ws.addCell(label1);
}
} catch (RowsExceededException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
public class Info {
//public static String popheight = "alliframe.height=document.body.clientHeight+";
public static String popheight = "alliframe.style.height=document.body.scrollHeight+";
public static HashMap getUser(HttpServletRequest request)
{
HashMap map = (HashMap)(request.getSession().getAttribute("username")==null?request.getSession().getAttribute("user"):request.getSession().getAttribute("username"));
return map;
}
public static int getBetweenDayNumber(String dateA, String dateB) {
long dayNumber = 0;
//1小时=60分钟=3600秒=3600000
long mins = 60L * 1000L;
//long day= 24L * 60L * 60L * 1000L;计算天数之差
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm");
try {
java.util.Date d1 = df.parse(dateA);
java.util.Date d2 = df.parse(dateB);
dayNumber = (d2.getTime() - d1.getTime()) / mins;
} catch (Exception e) {
e.printStackTrace();
}
return (int) dayNumber;
}
public static void main(String[] g )
{
}
try {
wrt = response.getWriter();
} catch (IOException e) {
// TODO Auto-generated catch block
e.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 block
e.printStackTrace();
}
}
public String getCols(String table)
{
String str = "";
Connection conn = this.getConn();
try {
Statement st = conn.createStatement();
protected int currentPage;
// 一页长度
protected int pageSize;
// 总页数
protected long pageNumber;
// 总记录数
protected long count;
// 数据
protected Collection collection;
// 数据查询对象
protected CommDAO dao = new CommDAO();
// 表现层代码
protected String info;
// 请求路径
protected String path;
// 服务器请求对象
protected HttpServletRequest request;
/*
* 仅仅只是加到路径中去
*/
protected String parameter = "";
/**
*
* @param 下一页的分页链接
* @param 一页最大记录数
* @param 当前HttpServletRequest对象
* @param 数据库操作对象
*/
protected PageManager(String path, int pageSize, HttpServletRequest request) {
// 任意一个dao都行
this.currentPage = 1;
this.pageNumber = 1;
this.count = 0;
this.pageSize = pageSize <= 0 ? DEFAULTPAGESIZE : pageSize;
this.request = request;
this.path = path;
request.setAttribute("page", this);
try {
return jscode;
}
public static String generalFileName(String srcFileName) {
try{
int index=srcFileName.lastIndexOf(".");
return StrUtil.generalSrid()+srcFileName.substring(index).toLowerCase();
}catch(Exception e){
return StrUtil.generalSrid();
}
}
public synchronized static String getID() {
Random random = new Random();
StringBuffer ret = new StringBuffer(20);
java.util.Date date = new java.util.Date();
java.text.SimpleDateFormat format = new java.text.SimpleDateFormat("MMddHHmmss", java.util.Locale.CHINA);
ret.append(format.format(date));
String rand = String.valueOf(Math.abs(random.nextInt()));
//ret.append(getDateStr());
ret.append(rand.substring(0,4));
return ret.toString();
}
public static String getImgUpInfo(int height)
{
String jscode = "";
jscode+="<img style=\"cursor: pointer;margin:3px\" οnclick=\"uploadimg()\" src=\"js/nopic.jpg\" id=txt height=\""+height+"\"/>";
jscode+="<input type=hidden name=\"filename\" id=\"filename\" value=\"\" />";
return jscode;
}
public static String getImgUpInfo2(int height)
{
String jscode = "";
jscode+="<img style=\"cursor: hand\" οnclick=\"uploadimg2()\" src=\"js/nopic.jpg\" id=txt2 height=\""+height+"\"/>";
jscode+="<input type=hidden name=\"filename2\" id=\"filename2\" value=\"\" />";
return jscode;
}
/**
* Initialization of the servlet. <br>
*
* @throws ServletException if an error occurs
*/
public void init() throws ServletException {
// Put your code here
}
}
public class SetChar extends HttpServlet implements Filter {
private FilterConfig filterConfig;
// Handle the passed-in FilterConfig
public void init(FilterConfig filterConfig) throws ServletException {
this.filterConfig = filterConfig;
}
// Process the request/response pair
public void doFilter(ServletRequest request, ServletResponse response,
FilterChain filterChain) {
try {
//request.setCharacterEncoding("UTF-8");
HttpServletRequest req = (HttpServletRequest) request;
if (req.getMethod().equalsIgnoreCase("get")) {
this.encoding(req);
}
response.setCharacterEncoding("UTF-8");
request.setCharacterEncoding("UTF-8");
filterChain.doFilter(request, response);
} catch (ServletException sx) {
filterConfig.getServletContext().log(sx.getMessage());
} catch (IOException iox) {
filterConfig.getServletContext().log(iox.getMessage());
}
}
private void encoding(HttpServletRequest request) {
Iterator iter = request.getParameterMap().values().iterator();
while (iter.hasNext()) {
String[] parames = (String[]) iter.next();
for (int i = 0; i < parames.length; i++) {
jscode+=" for(var i=0;i<radios.length;i++)\n";
jscode+=" {\n";
jscode+=" if(\""+str2+"\".indexOf(radios[i].value)>-1&&radios[i].id.indexOf('choosebox')==-1)\n";
jscode+=" {\n";
jscode+=" radios[i].checked=\"checked\";\n";
if(str2.indexOf(" - ")>-1){
for(String strch:str2.split(" ~ ")){
String strchname = strch.substring(0,strch.lastIndexOf(" - "));
jscode+=" if(document.getElementsByName('"+strchname+"').length>0)\n";
jscode+=" {\n";
jscode+=" document.getElementsByName('"+strchname+"')[0].value='"+strch.substring(strch.lastIndexOf(":")+1)+"';\n";
jscode+=" }\n";
}
}
jscode+=" }\n";
jscode+=" }\n";
jscode+=" }\n";
jscode+=" if(radios.type=='select'){\n";
jscode+=" "+formname+"."+str1+".value=\""+str2+"\";\n";
jscode+=" }\n";
jscode+=" }else{\n";
jscode+=" if("+formname+"."+str1+")\n";
jscode+="{\n";
jscode+=""+formname+"."+str1+".value=\""+str2+"\";\n";
jscode+="}\n";
jscode+="}\n";
jscode+="if(document.getElementById(\"txt\"))\n";
jscode+="{\n";
jscode+="document.getElementById(\"txt\").src=\"upfile/"+map.get("filename")+"\";\n";
jscode+="}\n";
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)
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("UTF-8");
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);
*/
protected String parameter = "";
/**
*
* @param 下一页的分页链接
* @param 一页最大记录数
* @param 当前HttpServletRequest对象
* @param 数据库操作对象
*/
protected PageManager(String path, int pageSize, HttpServletRequest request) {
// 任意一个dao都行
this.currentPage = 1;
this.pageNumber = 1;
this.count = 0;
this.pageSize = pageSize <= 0 ? DEFAULTPAGESIZE : pageSize;
this.request = request;
this.path = path;
request.setAttribute("page", this);
try {
this.currentPage = Integer.parseInt(request
.getParameter("currentPage")) <= 0 ? 1 : Integer
.parseInt(request.getParameter("currentPage"));
} catch (Exception e) {
try {
this.currentPage = Integer.parseInt((String) request
.getSession().getAttribute("currentPage"));
} catch (Exception e1) {
this.currentPage = 1;
}
}
}
/**
*
* @param 下一页的分页链接
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("UTF-8");
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) {
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);
// TODO Auto-generated catch block
e.printStackTrace();
}
return list.get(0);
}
public HashMap getmaps(String nzd,String zdz,String table)
{
List<HashMap> 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 block
e.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<String> collist = new ArrayList();
String sql = "insert into "+tablename+"(";
{
if(str.indexOf("~")>-1){
String zdstr = str.split("~")[0];
String zdnamestr = str.split("~")[1].equals("无名")?"":(str.split("~")[1]+":");
optionstr+=zdnamestr+permap.get(zdstr)+" - ";
}else{
optionstr+=permap.get(str);
}
}
if(optionstr.length()>0)optionstr=optionstr.substring(0,optionstr.length()-3);
optionstr+="',";
checkbox+= optionstr;
}
if(checkbox.length()>0)checkbox=checkbox.substring(0,checkbox.length()-1);
return checkbox;
}
public static String getcheckboxDk(String name,String tablename,String zdname,String nstr,String where)
{
String checkbox="";
int i=0;
for(HashMap permap:new CommDAO().select("select * from "+tablename+" where "+where+" order by id desc")){
String optionstr = "";
for(String str:zdname.split(";"))
{
String zdstr = str.split("~")[0];
String zdnamestr = str.split("~")[1].equals("无名")?"":(str.split("~")[1]+":");
optionstr+=zdnamestr+permap.get(zdstr)+" - ";
}
if(optionstr.length()>0)optionstr=optionstr.substring(0,optionstr.length()-3);
String nbs = "";
if(i>0)nbs=" ";
checkbox+="<label>"+nbs+"<input type='checkbox' name='"+name+"' value=\""+optionstr+"\">"+optionstr+"</label> \n";
checkbox+="<label> - "+nstr+" <input type='text' size='5' name='"+optionstr+"' value=\"\"></label><br />\n";
i++;
}
checkbox+="<input type=hidden name='"+name+"' value='' /><input type=hidden name='dk-"+name+"-value' value='"+nstr+"' />";
return checkbox;
}
public static String getFileUpInfo()
{
String jscode = "";
jscode+="<font οnclick=\"uploaddoc()\" src=\"js/nopic.jpg\" style='cursor:hand' id=txt >点击此处上传</font>";
public HashMap getmap(String id,String table)
{
List<HashMap> 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 block
e.printStackTrace();
}
return list.get(0);
}
public HashMap getmaps(String nzd,String zdz,String table)
{
List<HashMap> 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);