基于javaweb+mysql的jsp+servlet旅游管理系统(java+jsp+html5+bootstrap+servlet+mysql)
运行环境
Java≥8、MySQL≥5.7、Tomcat≥8
开发工具
eclipse/idea/myeclipse/sts等均可配置运行
适用
课程设计,大作业,毕业设计,项目练习,学习演示等
功能说明
基于javaweb+mysql的JSP+Servlet旅游管理系统(java+jsp+html5+bootstrap+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项目:否;
技术栈
HTML5+Ajax+CSS+JavaScript+BootStrap+jQuery+servlet+mysql
使用说明
- 使用Navicat或者其它工具,在mysql中创建对应名称的数据库,并导入项目的sql文件; 2. 使用IDEA/Eclipse/MyEclipse导入项目,Eclipse/MyEclipse导入时,若为maven项目请选择maven; 若为maven项目,导入成功后请执行maven clean;maven install命令,然后运行; 3. 将项目中util/db.properties配置文件中的数据库配置改为自己的配置; 4. 运行项目,前台运行地址输入http://localhost:8080/travel 登录 后台运行地址输入http://localhost:8080/travel/admin 登录 管理员账号/密码:admin/admin
throws ServletException, IOException {
// TODO Auto-generated method stub
doGet(request, response);
}
}
/**
* Servlet implementation class BannerDel
* 根据Id删除轮播图片
*/
@WebServlet("/admin/BannerDel")
public class BannerDel extends HttpServlet {
private static final long serialVersionUID = 1L;
BanOperator banOperator = new BanOperator();
/**
* @see HttpServlet#HttpServlet()
*/
public BannerDel() {
super();
// TODO Auto-generated constructor stub
}
/**
try {
List<Info> list = infoOperator.listMore(offset, size);
for (int i = 0; i < list.size(); i++) {
// Json对象
JSONObject json = new JSONObject();
// 查询结果集
Info info = list.get(i);
/*
* json.put("picname", banner.getBanname());
* json.put("pictitle", banner.getBantitle());
*/
json.put("info_id", info.getInfo_id());
json.put("info_title", info.getInfo_title());
json.put("info_txt", info.getInfo_txt());
json.put("info_tag", info.getInfo_tag());
json.put("info_pic", info.getInfo_pic());
json.put("info_url", info.getInfo_url());
json.put("info_date", info.getInfo_date());
System.out.println("InfoShow---:"+info.getInfo_date());
json.put("info_order", info.getInfo_order());
// 将Json对象放入数组
infoMore.add(json);
}
// 传到页面
out.print(infoMore);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
out.close();
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
* response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
// TODO Auto-generated method stub
doGet(request, response);
}
}
out.println("<TABLE BORDER=1>");
out.println("<TR><TD>表单项名(FieldName)</TD><TD>" + file.getFieldName() + "</TD></TR>");
out.println("<TR><TD>文件长度(Size)</TD><TD>" + file.getSize() + "</TD></TR>");
out.println("<TR><TD>文件名(FileName)</TD><TD>" + file.getFileName() + "</TD></TR>");
out.println("<TR><TD>文件扩展名(FileExt)</TD><TD>" + file.getFileExt() + "</TD></TR>");
out.println("<TR><TD>文件全名(FilePathName)</TD><TD>" + file.getFilePathName() + "</TD></TR>");
out.println("</TABLE><BR/>");*/
}
/*
* // 将文件另存为 try { file.saveAs("/image/banner" + file.getFileName(),
* SmartUpload.SAVE_VIRTUAL); file.saveAs("E:/Web//" +
* file.getFileName(), SmartUpload.SAVE_PHYSICAL); } catch
* (SmartUploadException e) { // TODO Auto-generated catch block
* e.printStackTrace(); }
*/
}
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
doGet(request, response);
}
}
/**
* Servlet implementation class BannerEdit
*/
@WebServlet("/admin/BannerEdit")
public class BannerEdit extends HttpServlet {
/**
* Servlet implementation class ScenByName
* 根据景点名来查找景点
*/
@WebServlet("/admin/ScenByName")
public class ScenByName extends HttpServlet {
private static final long serialVersionUID = 1L;
ScenOperator scenOperator=new ScenOperator();
/**
* @see HttpServlet#HttpServlet()
*/
public ScenByName() {
super();
// TODO Auto-generated constructor stub
}
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
request.setCharacterEncoding("utf-8");
response.setContentType("text/html;charset=utf-8");
//Ajax发送Url乱码解决的问题
String scenname=new String((request.getParameter("scenname")).getBytes("iso-8859-1"),"UTF-8");
PrintWriter out=response.getWriter();
System.out.println("ScenByName----"+scenname);
out.println("</TABLE><BR/>");*/
}
/*
* // 将文件另存为 try { file.saveAs("/image/banner" + file.getFileName(),
* SmartUpload.SAVE_VIRTUAL); file.saveAs("E:/Web//" +
* file.getFileName(), SmartUpload.SAVE_PHYSICAL); } catch
* (SmartUploadException e) { // TODO Auto-generated catch block
* e.printStackTrace(); }
*/
}
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
* response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
// TODO Auto-generated method stub
doGet(request, response);
}
}
}
}
/**
* Servlet implementation class BannerAdd
*/
@WebServlet("/admin/BannerAdd")
public class BannerAdd extends HttpServlet {
private static final long serialVersionUID = 1L;
BanOperator banOperator = new BanOperator();
/**
* @see HttpServlet#HttpServlet()
*/
public BannerAdd() {
super();
// TODO Auto-generated constructor stub
}
e.printStackTrace();
}
// 将上传的文件全部保存到指定目录
// 图片轮播的路径
try {
count = su.save("/image/banner");
} catch (SmartUploadException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println(count + "个文件上传成功!");
// 利用Request对象获取参数之值
// 逐一提取上传文件信息,同时可保存文件
for (int i = 0; i < su.getFiles().getCount(); i++) {
File file = su.getFiles().getFile(i);
// 若文件不存在则继续
if (file.isMissing()) {
continue;
}
banname = su.getRequest().getParameter("ban-name");
bantitle = su.getRequest().getParameter("ban-title");
banpath = "image/banner/" + file.getFileName();
banner = new Banner(banname, bantitle, banpath);
if (banOperator.addBan(banner)) {
System.out.println("getFileName***--" + file.getFilePathName());
out.flush();// 清空缓存
out.println("<script>");// 输出script标签
out.println("alert('轮播图图片上传成功!');");// js语句:输出alert语句
out.println("history.back();");// js语句:输出网页回退语句
out.println("</script>");// 输出script结尾标签
// 显示当前文件信息
/*out.println("轮播图图片上传成功");
out.println("<br/>图片名:" + su.getRequest().getParameter("ban-name") + "<br/><br/>");
out.println("<br/>标题名:" + su.getRequest().getParameter("ban-title") + "<br/><br/>");
out.println("<br/>标题名:" + "image/banner/" + file.getFileName() + "<br/><br/>");
out.println("<TABLE BORDER=1>");
out.println("<TR><TD>表单项名(FieldName)</TD><TD>" + file.getFieldName() + "</TD></TR>");
out.println("<TR><TD>文件长度(Size)</TD><TD>" + file.getSize() + "</TD></TR>");
out.println("<TR><TD>文件名(FileName)</TD><TD>" + file.getFileName() + "</TD></TR>");
/**
* Servlet implementation class ScenDel
* 删除景点
*/
@WebServlet("/admin/ScenDel")
public class ScenDel extends HttpServlet {
private static final long serialVersionUID = 1L;
ScenOperator scenOperator=new ScenOperator();
/**
* @see HttpServlet#HttpServlet()
*/
public ScenDel() {
super();
// TODO Auto-generated constructor stub
}
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
request.setCharacterEncoding("UTF-8");
response.setContentType("text/html;charset=UTF-8");
PrintWriter out=response.getWriter();
// Json数组
JSONArray scenMore = new JSONArray();
try {
List<Scen> list = scenOperator.listMore(offset, size);
for (int i = 0; i < list.size(); i++) {
// Json对象
JSONObject json = new JSONObject();
// 查询结果集
Scen scen = list.get(i);
/*
* json.put("picname", banner.getBanname());
* json.put("pictitle", banner.getBantitle());
*/
json.put("scenname", scen.getScenname());
json.put("scenlevel",scen.getScenlevel());
json.put("scentitle", scen.getScentitle());
json.put("scenadd", scen.getScenadd());
json.put("scenurl", scen.getScenurl());
json.put("scenpic", scen.getPicpath());
json.put("scenid", scen.getScenid());
// 将Json对象放入数组
scenMore.add(json);
}
// 传到页面
out.print(scenMore);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
out.close();
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
* response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response)
System.out.println("用户名:" + username);
System.out.println("密 码:" + password);
//response.sendRedirect("login.jsp");
out.flush();//清空缓存
out.println("<script>");//输出script标签
out.println("alert('-*-*-登录失败!密码不正确!');");//js语句:输出alert语句
out.println("history.back();");//js语句:输出网页回退语句
out.println("</script>");//输出script结尾标签
}
}
else {
System.out.println("-*-*-登录失败!用户名不存在!");
System.out.println("用户名:" + username);
System.out.println("密 码:" + password);
//response.sendRedirect("login.jsp");
out.flush();//清空缓存
out.println("<script>");//输出script标签
out.println("alert('-*-*-登录失败!用户名不存在!');");//js语句:输出alert语句
out.println("history.back();");//js语句:输出网页回退语句
out.println("</script>");//输出script结尾标签
// 做重定向到登录页面
//response.sendRedirect("login.jsp");
}
out.close();
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
* response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
// TODO Auto-generated method stub
doGet(request, response);
}
}
// 上传文件
try {
su.upload();
} catch (SmartUploadException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
// 将上传的文件全部保存到指定目录
// 图片轮播的路径
try {
count = su.save("/image/banner");
} catch (SmartUploadException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println(count + "个文件上传成功!");
// 利用Request对象获取参数之值
// 逐一提取上传文件信息,同时可保存文件
for (int i = 0; i < su.getFiles().getCount(); i++) {
File file = su.getFiles().getFile(i);
// 若文件不存在则继续
if (file.isMissing()) {
continue;
}
banname = su.getRequest().getParameter("ban-name");
bantitle = su.getRequest().getParameter("ban-title");
banpath = "image/banner/" + file.getFileName();
banner = new Banner(banname, bantitle, banpath);
if (banOperator.addBan(banner)) {
System.out.println("getFileName***--" + file.getFilePathName());
out.flush();// 清空缓存
out.println("<script>");// 输出script标签
out.println("alert('轮播图图片上传成功!');");// js语句:输出alert语句
out.println("history.back();");// js语句:输出网页回退语句
out.println("</script>");// 输出script结尾标签
// 显示当前文件信息
/*out.println("轮播图图片上传成功");
out.println("<br/>图片名:" + su.getRequest().getParameter("ban-name") + "<br/><br/>");
out.println("<br/>标题名:" + su.getRequest().getParameter("ban-title") + "<br/><br/>");
out.println("<br/>标题名:" + "image/banner/" + file.getFileName() + "<br/><br/>");
/*
* // 将文件另存为 try { file.saveAs("/image/banner" + file.getFileName(),
* SmartUpload.SAVE_VIRTUAL); file.saveAs("E:/Web//" +
* file.getFileName(), SmartUpload.SAVE_PHYSICAL); } catch
* (SmartUploadException e) { // TODO Auto-generated catch block
* e.printStackTrace(); }
*/
}
}
}
/**
* Servlet implementation class UserAdd
*/
@WebServlet("/admin/UserAdd")
public class UserAdd extends HttpServlet {
private static final long serialVersionUID = 1L;
UserOperator userOperator = new UserOperator();
/**
* @see HttpServlet#HttpServlet()
*/
public UserAdd() {
super();
// TODO Auto-generated constructor stub
}
picpath = "image/scen/" + file.getFileName();
scenadd = su.getRequest().getParameter("scen-add");
scennameen = su.getRequest().getParameter("scen-name-en");
scenorder=Integer.parseInt(su.getRequest().getParameter("scen-order"));
scenurl=su.getRequest().getParameter("scen-url");
scen = new Scen(scenname, scenintro, scenlevel, scentitle, scenfeature, scentraff, scenmap, picpath, scenadd, scennameen, scenorder, scenurl);
if (scenOperator.addScen(scen)) {
/*---------------------------------------------------------*/
//上传成功之后,jsp页面显示弹出弹出框
System.out.println("getFileName***--" + file.getFilePathName());
out.flush();// 清空缓存
out.println("<script>");// 输出script标签
out.println("alert('景点图片上传成功!');");// js语句:输出alert语句
out.println("history.back();");// js语句:输出网页回退语句
out.println("</script>");// 输出script结尾标签
/*
out.println("景点图片上传成功");
out.println("<br/>图片名:" + su.getRequest().getParameter("scen-name") + "<br/><br/>");
out.println("<br/>标题名:" + su.getRequest().getParameter("scen-title") + "<br/><br/>");
out.println("<br/>标题名:" + "image/scen/" + file.getFileName() + "<br/><br/>");
// 显示当前文件信息
out.println("<TABLE BORDER=1>");
out.println("<TR><TD>表单项名(FieldName)</TD><TD>" + file.getFieldName() + "</TD></TR>");
out.println("<TR><TD>文件长度(Size)</TD><TD>" + file.getSize() + "</TD></TR>");
out.println("<TR><TD>文件名(FileName)</TD><TD>" + file.getFileName() + "</TD></TR>");
out.println("<TR><TD>文件扩展名(FileExt)</TD><TD>" + file.getFileExt() + "</TD></TR>");
out.println("<TR><TD>文件全名(FilePathName)</TD><TD>" + file.getFilePathName() + "</TD></TR>");
out.println("</TABLE><BR/>");*/
}
/*
* // 将文件另存为 try { file.saveAs("/image/banner" + file.getFileName(),
* SmartUpload.SAVE_VIRTUAL); file.saveAs("E:/Web//" +
* file.getFileName(), SmartUpload.SAVE_PHYSICAL); } catch
* (SmartUploadException e) { // TODO Auto-generated catch block
* e.printStackTrace(); }
*/
}
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
* response)
}
/**
* Servlet implementation class UserAdd
*/
@WebServlet("/admin/UserAdd")
public class UserAdd extends HttpServlet {
private static final long serialVersionUID = 1L;
UserOperator userOperator = new UserOperator();
/**
* @see HttpServlet#HttpServlet()
*/
public UserAdd() {
super();
// TODO Auto-generated constructor stub
}
// 获取客户端IP地址
public static String getIpAddress(HttpServletRequest request) {
String ip = request.getHeader("x-forwarded-for");
if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
ip = request.getHeader("Proxy-Client-IP");
}
if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
ip = request.getHeader("WL-Proxy-Client-IP");
}
if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
ip = request.getHeader("HTTP_CLIENT_IP");
}
if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
ip = request.getHeader("HTTP_X_FORWARDED_FOR");
}
if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
ip = request.getRemoteAddr();
}
return ip;
}
/*
out.println("资讯图片上传成功");
out.println("<br/>图片名:" + info_pic + "<br/><br/>");
out.println("<br/>标题名:" + su.getRequest().getParameter("info_title") + "<br/><br/>");
out.println("<br/>标签:" + info_tag + "<br/><br/>");
System.out.println("getFileName----" + file.getFilePathName());
// 显示当前文件信息
out.println("<TABLE BORDER=1>");
out.println("<TR><TD>表单项名(FieldName)</TD><TD>" + file.getFieldName() + "</TD></TR>");
out.println("<TR><TD>文件长度(Size)</TD><TD>" + file.getSize() + "</TD></TR>");
out.println("<TR><TD>文件名(FileName)</TD><TD>" + file.getFileName() + "</TD></TR>");
out.println("<TR><TD>文件扩展名(FileExt)</TD><TD>" + file.getFileExt() + "</TD></TR>");
out.println("<TR><TD>文件全名(FilePathName)</TD><TD>" + file.getFilePathName() + "</TD></TR>");
out.println("</TABLE><BR/>");*/
}
/*
* // 将文件另存为 try { file.saveAs("/image/banner" + file.getFileName(),
* SmartUpload.SAVE_VIRTUAL); file.saveAs("E:/Web//" +
* file.getFileName(), SmartUpload.SAVE_PHYSICAL); } catch
* (SmartUploadException e) { // TODO Auto-generated catch block
* e.printStackTrace(); }
*/
}
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
doGet(request, response);
}
}
}
if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
ip = request.getHeader("WL-Proxy-Client-IP");
}
if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
ip = request.getHeader("HTTP_CLIENT_IP");
}
if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
ip = request.getHeader("HTTP_X_FORWARDED_FOR");
}
if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
ip = request.getRemoteAddr();
}
return ip;
}
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
request.setCharacterEncoding("UTF-8");
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
int user_id = Integer.parseInt(request.getParameter("userid"));
String username = null;
String email = null;
String register_ip = null;
String gender = null;
username = request.getParameter("username");
email = request.getParameter("email");
register_ip = getIpAddress(request);
gender = request.getParameter("gender");
System.out.println("IpAddr" + register_ip);
User user=new User(user_id, username, email, register_ip, gender);
if (userOperator.editUser(user)) {
System.out.println("编辑成功!");
out.flush();// 清空缓存
out.println("<script>");// 输出script标签
out.println("alert('编辑成功!');");// js语句:输出alert语句
out.println("history.back();");// js语句:输出网页回退语句
/**
* Servlet implementation class ScenShow
*/
@WebServlet("/ScenShow")
public class ScenShow extends HttpServlet {
private static final long serialVersionUID = 1L;
ScenOperator scenOperator = new ScenOperator();
/**
* @see HttpServlet#HttpServlet()
*/
public ScenShow() {
super();
// TODO Auto-generated constructor stub
}
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
* response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
// TODO Auto-generated method stub
request.setCharacterEncoding("UTF-8");
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
System.out.println("*--------------------------------------------------*");
System.out.println("*---景点图----ScenShow");
int offset = Integer.parseInt(request.getParameter("offset"));
int size = Integer.parseInt(request.getParameter("size"));
// TODO Auto-generated method stub
request.setCharacterEncoding("UTF-8");
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
System.out.println("---资讯----InfoShow");
int offset = Integer.parseInt(request.getParameter("offset"));
int size = Integer.parseInt(request.getParameter("size"));
System.out.println("offset--" + offset + ",size---" + size);
// Json数组
JSONArray infoMore = new JSONArray();
try {
List<Info> list = infoOperator.listMore(offset, size);
for (int i = 0; i < list.size(); i++) {
// Json对象
JSONObject json = new JSONObject();
// 查询结果集
Info info = list.get(i);
/*
* json.put("picname", banner.getBanname());
* json.put("pictitle", banner.getBantitle());
*/
json.put("info_id", info.getInfo_id());
json.put("info_title", info.getInfo_title());
json.put("info_txt", info.getInfo_txt());
json.put("info_tag", info.getInfo_tag());
json.put("info_pic", info.getInfo_pic());
json.put("info_url", info.getInfo_url());
json.put("info_date", info.getInfo_date());
System.out.println("InfoShow---:"+info.getInfo_date());
json.put("info_order", info.getInfo_order());
// 将Json对象放入数组
infoMore.add(json);
}
// 传到页面
out.print(infoMore);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
out.close();
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
* response)