基于javaweb+mysql的jsp+servlet家政服务系统(java+jsp+jquery+servlet+mysql)
运行环境
Java≥8、MySQL≥5.7、Tomcat≥8
开发工具
eclipse/idea/myeclipse/sts等均可配置运行
适用
课程设计,大作业,毕业设计,项目练习,学习演示等
功能说明
基于javaweb+mysql的JSP+Servlet家政服务系统(java+jsp+jquery+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+jquery+Servlet+mysql
使用说明
- 使用Navicat或者其它工具,在mysql中创建对应名称的数据库,并导入项目的sql文件; 2. 使用IDEA/Eclipse/MyEclipse导入项目,Eclipse/MyEclipse导入时,若为maven项目请选择maven; 若为maven项目,导入成功后请执行maven clean;maven install命令,然后运行; 3. 将项目中dao/CommDAO.java配置文件中的数据库配置改为自己的配置; 4. 运行项目,输入localhost:8080/jsp_jzfw_site 登录
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);
if (request.getHeader("User-Agent").toLowerCase().indexOf("firefox") > 0){
try {
filename = new String(filename.getBytes("UTF-8"), "ISO8859-1");
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
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>
String a = it.next().toString();
label1.setString(a);
ws.addCell(label1);
jj++;
}
i++;
} catch (RowsExceededException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (WriteException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
try {
//从内存中写入文件中
wwb.write();
//关闭资源,释放内存
wwb.close();
} catch (IOException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
}
try {
response.sendRedirect("upload?filename=" + fileName.substring(fileName.lastIndexOf("/") + 1));
} catch (IOException e) {
e.printStackTrace();
}
}
public static String getcheckbox(String name, String tablename, String zdname, String where) {
String checkbox = "";
for (HashMap permap : new CommDAO().select("select * from " + tablename + " where " + where + " order by id desc")) {
String optionstr = "";
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("<div id=picViwer1 style='background-color: #ffffff' align=center></div><SCRIPT src='js/dynamicImage.js' type=text/javascript></SCRIPT>\n<script language=JavaScript>\n");
thePics1.append("var thePics1=\n'");
theLinks1.append("var theLinks1='");
theTexts1.append("var theTexts1='");
List<HashMap> 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 + "|");
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() {
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>
*
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("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{
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);
String sql1 = "select * from allusers where username='"+username+"' and pwd='"+password+"' ";
List<HashMap> userlist1 = dao.select(sql1);
if(userlist1.size()==1)
{
request.getSession(). setAttribute("username", userlist1.get(0).get("username"));
request.getSession(). setAttribute("cx", userlist1.get(0).get("cx"));
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"))
// 一页长度
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.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/uploaddoc2.jsp?docname="+filename, request, response);
} catch (Exception e1) {
e1.printStackTrace();
}
}
if(ac.equals("uploaddoc3"))
{
try {
String filename="";
request.setCharacterEncoding("UTF-8");
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();
} catch (WriteException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
//下面开始添加单元格
int i = 1;
for (List t : mlist) {
try {
Iterator it = t.iterator();
int jj = 0;
while (it.hasNext()) {
Label label1 = new Label(jj, i, "");
String a = it.next().toString();
label1.setString(a);
ws.addCell(label1);
jj++;
}
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();
} catch (WriteException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
//下面开始添加单元格
int i = 1;
for (List t : mlist) {
try {
Iterator it = t.iterator();
int jj = 0;
while (it.hasNext()) {
Label label1 = new Label(jj, i, "");
String a = it.next().toString();
label1.setString(a);
ws.addCell(label1);
jj++;
}
i++;
} catch (RowsExceededException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (WriteException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
try {
public class PageManager {
private PageManager() {
}
// 默认一页最大记录数
public static final int DEFAULTPAGESIZE = 20;
// 分页段
public static final int segment = 10;
// 当前页数
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;
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("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);
}
} 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 block
e.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 block
e.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) {
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);
radio += "<label><input type='radio' name='" + name + "' " + check + " value=\"" + optionstr + "\">" + optionstr + "</label>\n";
dxii++;
}
return radio;
}
public static void writeExcel(String fileName, String prosstr, java.util.List<List> plist, HttpServletRequest request, HttpServletResponse response) {
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);
}
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="";
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 (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;
}
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() {
}