基于javaweb+mysql的jsp+servlet校园自行车租赁管理系统(java+jsp+javascript+servlet+mysql)
运行环境
Java≥8、MySQL≥5.7、Tomcat≥8
开发工具
eclipse/idea/myeclipse/sts等均可配置运行
适用
课程设计,大作业,毕业设计,项目练习,学习演示等
功能说明
基于javaweb+mysql的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 登录
typemap.put(rsmd.getColumnName(j)+"---", rsmd.getColumnTypeName(j));
collist.add(rsmd.getColumnName(j));
sql+=rsmd.getColumnName(j)+",";
}
sql = sql.substring(0,sql.length()-1);
sql+=") values(";
rs.close();
st.close();
} catch (SQLException e) {
e.printStackTrace();
}
Enumeration enumeration = request.getParameterNames();
String names = ",";
while(enumeration.hasMoreElements())
{
names += enumeration.nextElement().toString()+",";
}
try {
Statement st = conn.createStatement();
for(String str:collist)
{
if(names.indexOf(","+str+",")>-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"))
{
{
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) {
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("UTF-8");
RequestContext requestContext = new ServletRequestContext(request);
if(FileUpload.isMultipartContent(requestContext)){
DiskFileItemFactory factory = new DiskFileItemFactory();
e.printStackTrace();
}
}
else
if (request.getHeader("User-Agent").toUpperCase().indexOf("MSIE") > 0){
try {
filename = URLEncoder.encode(filename, "UTF-8");
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
}
}
response.setContentType("text/plain");
response.setHeader("Location",filename);
response.reset();
response.setHeader("Cache-Control", "max-age=0" );
response.setHeader("Content-Disposition", "attachment; filename=" + filename);
try {
BufferedInputStream bis = null;
BufferedOutputStream bos = null;
OutputStream fos = null;
// File f = new File(request.getRealPath("/upfile/")+"/"+filename);
//System.out.println(f);
bis = new BufferedInputStream((InputStream)new FileInputStream(request.getRealPath("/upfile/")+"/"+filename));
fos = response.getOutputStream();
bos = new BufferedOutputStream(fos);
int bytesRead = 0;
byte[] buffer = new byte[5 * 1024];
while ((bytesRead = bis.read(buffer)) != -1) {
bos.write(buffer, 0, bytesRead);
}
bos.close();
bis.close();
fos.close();
new Info().delPic(request.getRealPath("/upfile/")+"/", filename);
} catch (Exception e) {
}finally{
}
}
/**
* 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++) {
try {
parames[i] = new String(parames[i].getBytes("iso8859-1"),
"UTF-8");
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
public class Upload extends HttpServlet {
/**
* Constructor of the object.
*/
public Upload() {
super();
}
/**
* Destruction of the servlet. <br>
*/
public void destroy() {
super.destroy(); // Just puts "destroy" string in log
// Put your code here
}
/**
* The doGet method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to get.
*
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
*/
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
this.doPost(request, response);
}
/**
* The doPost method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to post.
*
* @param request the request send by the client to the server
* @param response the response send by the server to the client
} 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 block
e.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 yonghuzhuce where yonghuming='"+username+"' and mima='"+password+"' and issh='是'";
}
else
{
sql1 = "select * from yuangongxinxi where gonghao='"+username+"' and mima='"+password+"'";
jscode+="if(document.getElementById(\"txt\"))\n";
jscode+="{\n";
jscode+="document.getElementById(\"txt\").src=\"upfile/"+map.get("filename")+"\";\n";
jscode+="}\n";
jscode+="if(document.getElementById(\"txt2\"))\n";
jscode+="{\n";
jscode+="document.getElementById(\"txt2\").src=\"upfile/"+map.get("filename2")+"\";\n";
jscode+="}\n";
jscode+="if(document.getElementById(\"txt3\"))\n";
jscode+="{\n";
jscode+="document.getElementById(\"txt3\").src=\"upfile/"+map.get("filename3")+"\";\n";
jscode+="}\n";
jscode+="if(document.getElementById(\"txt4\"))\n";
jscode+="{\n";
jscode+="document.getElementById(\"txt4\").src=\"upfile/"+map.get("filename4")+"\";\n";
jscode+="}\n";
jscode+="if(document.getElementById(\"txt5\"))\n";
jscode+="{\n";
jscode+="document.getElementById(\"txt5\").src=\"upfile/"+map.get("filename5")+"\";\n";
jscode+="}\n";
}
}
jscode+="}\n";
jscode+=" getPvalue();\n";
jscode+="</script>\n";
}catch (Exception e) {
e.printStackTrace();
}
return jscode;
}
}
public class MainCtrl extends HttpServlet {
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("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();
request.getSession(). setAttribute("username", userlist1.get(0).get("gonghao"));
}
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 zhandianguanliyuan where yonghuming='"+username+"' and mima='"+password+"'";
}
List<HashMap> userlist1 = dao.select(sql1);
if(userlist1.size()==1)
{
if (utype.equals("管理员"))
{
request.getSession(). setAttribute("username", userlist1.get(0).get("username"));
request.getSession(). setAttribute("cx", userlist1.get(0).get("cx"));
}
if (utype.equals("站点管理员"))
{
request.getSession(). setAttribute("username", userlist1.get(0).get("yonghuming"));
request.getSession(). setAttribute("zd", userlist1.get(0).get("zulinzhandian"));
request.getSession(). setAttribute("cx",utype );
}
gor("main.jsp", request, response);
}else{
jscode+="if(document.getElementById(\"txt\"))\n";
jscode+="{\n";
jscode+="document.getElementById(\"txt\").src=\"upfile/"+map.get("filename")+"\";\n";
jscode+="}\n";
jscode+="if(document.getElementById(\"txt2\"))\n";
jscode+="{\n";
jscode+="document.getElementById(\"txt2\").src=\"upfile/"+map.get("filename2")+"\";\n";
jscode+="}\n";
jscode+="if(document.getElementById(\"txt3\"))\n";
jscode+="{\n";
jscode+="document.getElementById(\"txt3\").src=\"upfile/"+map.get("filename3")+"\";\n";
jscode+="}\n";
jscode+="if(document.getElementById(\"txt4\"))\n";
jscode+="{\n";
jscode+="document.getElementById(\"txt4\").src=\"upfile/"+map.get("filename4")+"\";\n";
jscode+="}\n";
jscode+="if(document.getElementById(\"txt5\"))\n";
jscode+="{\n";
jscode+="document.getElementById(\"txt5\").src=\"upfile/"+map.get("filename5")+"\";\n";
jscode+="}\n";
}
}
jscode+="}\n";
jscode+=" getPvalue();\n";
jscode+="</script>\n";
}catch (Exception e) {
e.printStackTrace();
}
return jscode;
}
go("/admin/"+page+"?docname="+filename, request, response);
} catch (Exception e1) {
e1.printStackTrace();
}
}
if(ac.equals("uploadimg"))
{
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) {
e.printStackTrace();
}
}else{
}
}
}
go("/js/uploadimg.jsp?filename="+filename, request, response);
} catch (Exception e1) {
e1.printStackTrace();
}
}
if(ac.equals("uploadimg2"))
{
try {
String filename="";
if(sql.equals("show tables"))
list = select("select table_name from INFORMATION_SCHEMA.tables");
else
e.printStackTrace();
}
return list;
}
public List<List> selectforlist(String sql)
{
List<List> list = new ArrayList();
try {
Statement st = conn.createStatement();
ResultSet rs = st.executeQuery(sql);
ResultSetMetaData rsmd = rs.getMetaData();
while(rs.next())
{
List<String> 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 block
e.printStackTrace();
}
return list;
}
public void close()
{
}
/**
if(start==-1) {
break;
}
subLowcase1=sourceLowcase.substring(0,start);
sub1=source.substring(0,start);
end=sourceLowcase.indexOf(to,start);
if(end==-1){
end=sourceLowcase.indexOf("/>",start);
if(end==-1) {
done=false;
}
}
else{
end=end+to.length();
subLowcase2=sourceLowcase.substring(end,source.length());
sub2=source.substring(end,source.length());
sourceLowcase=subLowcase1+subLowcase2;
source=sub1+sub2;
}
//System.out.println(start+" "+end);
}
return source;
}
public static void delPic(String path,String img)
{
if(img!=null)
{
if(!img.equals(""))
{
File file1=new File(path + "/" + img);
if(file1.exists() ) {
//file1.deleteOnExit();
//file1.delete();
}}}
}
}
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("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);
return pageNumber;
}
public int getPageSize() {
return pageSize;
}
public String getInfo() {
return info;
}
public static ArrayList<HashMap> getPages(String url,int pagesize,String sql,HttpServletRequest request )
{
PageManager pageManager = PageManager.getPage(url, pagesize, request);
pageManager.doList(sql);
PageManager bean = (PageManager) request.getAttribute("page");
ArrayList<HashMap> nlist = (ArrayList) bean.getCollection();
return nlist;
}
}
public class Upload extends HttpServlet {
/**
* Constructor of the object.
*/
public Upload() {
{
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();