基于javaweb+mysql的jsp+servlet旅游管理系统(java+jsp+html+bootstrap+servlet+mysql)
私信源码获取及调试交流
运行环境
Java≥8、MySQL≥5.7、Tomcat≥8
开发工具
eclipse/idea/myeclipse/sts等均可配置运行
适用
课程设计,大作业,毕业设计,项目练习,学习演示等
功能说明
基于javaweb的JSP+Servlet旅游管理系统(java+jsp+html+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
/**
* 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);
//JSON数组
JSONArray scenJson = new JSONArray();
try {
//得到模糊查询的结果集
List<Scen> list = scenOperator.findScenByName(scenname);
//遍历该集合
for (int i = 0; i < list.size(); i++) {
// Json对象
JSONObject json=new JSONObject();
// 查询结果集
* 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();
// request.getRemoteAddr();
System.out.println("*--------------------------------------------------*");
System.out.println("新增留言:MsgAdd");
String author = null;
String msg_text = null;
String msg_ip = null;
String email = null;
author = request.getParameter("author");
email = request.getParameter("email");
msg_text = request.getParameter("msg_text");
msg_ip = getIpAddress(request);
System.out.println("IpAddr" + msg_ip);
Msg msg = new Msg(author, msg_text, msg_ip, msg_ip, email);
if (msgOperator.addMsg(msg)) {
System.out.println("留言成功!");
out.flush();// 清空缓存
out.println("<script>");// 输出script标签
out.println("alert('留言成功!');");// js语句:输出alert语句
out.println("history.back();");// js语句:输出网页回退语句
out.println("</script>");// 输出script结尾标签
}
else {
System.out.println("留言失败!");
out.flush();// 清空缓存
out.println("<script>");// 输出script标签
out.println("alert('留言失败!');");// js语句:输出alert语句
out.println("history.back();");// js语句:输出网页回退语句
out.println("</script>");// 输出script结尾标签
}
out.close();
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
* response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response)
/**
* @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();
// 上下文
PageContext pageContext = JspFactory.getDefaultFactory().getPageContext(this, request, response, null, true,
8 * 1024, true);
// 上传到目录个数
int count = 0;
String info_title = null;
String info_txt = null;
String info_tag = null;
String info_pic = null;
String info_url = null;
int info_order = 0;
// 资讯实体对象
Info info = null;
System.out.println("资讯图片上传--/admin/InfoAdd");
// 新建一个SmartUpload对象
SmartUpload su = new SmartUpload();
// 上传初始化
su.initialize(pageContext);
// 设置上传限制
// 1.限制每个上传文件的最大长度为10MB
su.setMaxFileSize(10 * 1024 * 1024);
// 2.限制总上传文件的长度
su.setTotalMaxFileSize(30 * 1024 * 1024);
// 3.设定允许上传的文件
su.setAllowedFilesList("gif,jpg,png,jpeg,bmp,ico");
// 4.设定禁止上传的文件
try {
su.setDeniedFilesList("exe,bat,jsp,htm,html,,");
} catch (SQLException e) {
// TODO Auto-generated catch block
System.out.println("不允许上传此类文件");
e.printStackTrace();
}
// 上传文件
try {
su.upload();
File file = new File(request.getServletContext().getRealPath(getServletInfo())+"/"+infopic);
//路径和文件名称
System.out.println(file.getPath());
System.out.println(file.getName());
//如果文件存在
if (file.exists()) {
//file.delete();
System.out.println("删除成功");
out.flush();// 清空缓存
out.println("<script>");// 输出script标签
out.println("alert('删除成功!');");// js语句:输出alert语句
out.println("history.back();");// js语句:输出网页回退语句
out.println("</script>");// 输出script结尾标签
}
else {
System.out.println("删除失败,文件不存在!");
out.flush();// 清空缓存
out.println("<script>");// 输出script标签
out.println("alert('删除失败,文件不存在!');");// js语句:输出alert语句
out.println("history.back();");// js语句:输出网页回退语句
out.println("</script>");// 输出script结尾标签
}
}
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("alert('删除成功!');");// js语句:输出alert语句
out.println("history.back();");// js语句:输出网页回退语句
out.println("</script>");// 输出script结尾标签
} else {
System.out.println("删除失败,文件不存在!");
out.flush();// 清空缓存
out.println("<script>");// 输出script标签
out.println("alert('删除失败,文件不存在!');");// js语句:输出alert语句
out.println("history.back();");// js语句:输出网页回退语句
out.println("</script>");// 输出script结尾标签
}
}
out.close();
}
}
/**
* 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
}
String info_tag = null;
String info_pic = null;
String info_url = null;
String info_date = null;
int info_order = 0;
// 资讯实体对象
Info info = null;
System.out.println("资讯图片上传");
// 新建一个SmartUpload对象
SmartUpload su = new SmartUpload();
// 上传初始化
su.initialize(pageContext);
// 设置上传限制
// 1.限制每个上传文件的最大长度为10MB
su.setMaxFileSize(10 * 1024 * 1024);
// 2.限制总上传文件的长度
su.setTotalMaxFileSize(30 * 1024 * 1024);
// 3.设定允许上传的文件
su.setAllowedFilesList("gif,jpg,png,jpeg,bmp,ico");
// 4.设定禁止上传的文件
try {
su.setDeniedFilesList("exe,bat,jsp,htm,html,,");
} catch (SQLException e) {
// TODO Auto-generated catch block
System.out.println("不允许上传此类文件");
e.printStackTrace();
}
// 上传文件
try {
su.upload();
} catch (SmartUploadException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
// 将上传的文件全部保存到指定目录
// 图片轮播的路径
try {
count = su.save("/image/info");
} catch (SmartUploadException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println(count + "个文件上传成功!");
// 利用Request对象获取参数之值
register_ip = getIpAddress(request);
gender = request.getParameter("gender");
System.out.println("IpAddr" + register_ip);
User user = new User(username, password, email, register_ip, gender);
if (userOperator.addUser(user)) {
System.out.println("添加成功!");
out.flush();//清空缓存
out.println("<script>");//输出script标签
out.println("alert('添加成功!');");//js语句:输出alert语句
out.println("history.back();");//js语句:输出网页回退语句
out.println("</script>");//输出script结尾标签
}
else {
System.out.println("添加失败!");
out.flush();//清空缓存
out.println("<script>");//输出script标签
out.println("alert('添加失败!');");//js语句:输出alert语句
out.println("history.back();");//js语句:输出网页回退语句
out.println("</script>");//输出script结尾标签
}
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);
}
}
// 2.限制总上传文件的长度
su.setTotalMaxFileSize(30 * 1024 * 1024);
// 3.设定允许上传的文件
su.setAllowedFilesList("gif,jpg,png,jpeg,bmp,ico");
// 4.设定禁止上传的文件
try {
su.setDeniedFilesList("exe,bat,jsp,htm,html,,");
} catch (SQLException e) {
// TODO Auto-generated catch block
System.out.println("不允许上传此类文件");
e.printStackTrace();
}
// 上传文件
try {
su.upload();
} catch (SmartUploadException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
// 将上传的文件全部保存到指定目录
// 图片轮播的路径
try {
count = su.save("/image/info");
} 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;
}
info_title = su.getRequest().getParameter("info_title");
info_txt = su.getRequest().getParameter("info_txt");
info_tag = su.getRequest().getParameter("info_tag");
info_url = su.getRequest().getParameter("info_url");
info_order = Integer.parseInt(su.getRequest().getParameter("info_order"));
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)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
doGet(request, response);
}
System.out.println("*---景点图----ScenShow");
int offset = Integer.parseInt(request.getParameter("offset"));
int size = Integer.parseInt(request.getParameter("size"));
System.out.println("offset--"+offset+",size---"+size);
// 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)
throws ServletException, IOException {
// TODO Auto-generated method stub
*/
public InfoDel() {
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();
//删除资讯的ID
int infoid = Integer.parseInt(request.getParameter("infoid"));
//删除的文件名称
String infopic=request.getParameter("infopic");
System.out.println("/admin/InfoDel:" + infoid);
if (infoOperator.delInfo(infoid)) {
//获取要删除的图片或者文件的绝对路径
File file = new File(request.getServletContext().getRealPath(getServletInfo())+"/"+infopic);
//路径和文件名称
System.out.println(file.getPath());
System.out.println(file.getName());
//如果文件存在
if (file.exists()) {
//file.delete();
System.out.println("删除成功");
out.flush();// 清空缓存
out.println("<script>");// 输出script标签
out.println("alert('删除成功!');");// js语句:输出alert语句
out.println("history.back();");// js语句:输出网页回退语句
out.println("</script>");// 输出script结尾标签
}
else {
System.out.println("删除失败,文件不存在!");
out.flush();// 清空缓存
//file.delete();
System.out.println("删除成功");
out.flush();// 清空缓存
out.println("<script>");// 输出script标签
out.println("alert('删除成功!');");// js语句:输出alert语句
out.println("history.back();");// js语句:输出网页回退语句
out.println("</script>");// 输出script结尾标签
}
else {
System.out.println("删除失败,文件不存在!");
out.flush();// 清空缓存
out.println("<script>");// 输出script标签
out.println("alert('删除失败,文件不存在!');");// js语句:输出alert语句
out.println("history.back();");// js语句:输出网页回退语句
out.println("</script>");// 输出script结尾标签
}
}
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.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);
}
}
/**
* Servlet implementation class UserEdit
*/
@WebServlet("/admin/UserEdit")
public class UserEdit extends HttpServlet {
private static final long serialVersionUID = 1L;
UserOperator userOperator=new UserOperator();
/**
* @see HttpServlet#HttpServlet()
*/
public UserEdit() {
super();
// TODO Auto-generated constructor stub
}
// 获取客户端IP地址
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
doPost(request, response);
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
* response)
*/
protected void doPost(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();
// 上下文
PageContext pageContext = JspFactory.getDefaultFactory().getPageContext(this, request, response, null, true,
8 * 1024, true);
// 上传到目录个数
int count = 0;
String banname = null;
String bantitle = null;
String banpath = null;
Banner banner = null;
System.out.println("轮播图片上传");
// 新建一个SmartUpload对象
SmartUpload su = new SmartUpload();
// 上传初始化
su.initialize(pageContext);
// 设置上传限制
// 1.限制每个上传文件的最大长度为10MB
su.setMaxFileSize(10 * 1024 * 1024);
// 2.限制总上传文件的长度
/**
* Servlet implementation class MsgAdd
*/
@WebServlet("/MsgAdd")
public class MsgAdd extends HttpServlet {
private static final long serialVersionUID = 1L;
MsgOperator msgOperator = new MsgOperator();
/**
* @see HttpServlet#HttpServlet()
*/
public MsgAdd() {
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)) {
/**
* @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 InfoEdit
*/
@WebServlet("/admin/InfoEdit")
public class InfoEdit extends HttpServlet {
private static final long serialVersionUID = 1L;
InfoOperator infoOperator = new InfoOperator();
/**
* @see HttpServlet#HttpServlet()
*/
public InfoEdit() {
super();
// TODO Auto-generated constructor stub
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;
}
/**
* @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();
// request.getRemoteAddr();
System.out.println("*--------------------------------------------------*");
System.out.println("新增留言:MsgAdd");
String author = null;
String msg_text = null;
String msg_ip = null;
String email = null;
author = request.getParameter("author");
email = request.getParameter("email");