• java servlet大学生旅游网站的设计与开发源码


     博主介绍:✌在职Java研发工程师、专注于程序设计、源码分享、技术交流、专注于Java技术领域和毕业设计

    🍅文末获取源码联系🍅

    🍅CSDN官方推荐10W+JAVA技术人文章发布打卡社区🍅

    项目名称

    java servlet大学生旅游网站的设计与开发源码

    视频效果

    java servlet大学生旅游网站的设计与开发源码

    系统说明

    4.2.1 前台界面

    显示界面,其功能如下:

    • 洛阳旅游景区的信息显示:显示最近的动态的旅游景点,洛阳最近的相关新闻,等等。
    • 信息交互,可以提交一个消息函数,可以得到有关旅游景点和建议的网站系统。

    4.2.2 后台管理

    管理的背景下,其功能如下:

    • 个人信息管理:针对用户的信息和管理人员的信息可以进行维护;
    • 信息管理:上传的洛阳新闻信息,并可以删除和编辑以前的消息;
    • 景区管理:针对洛阳特色景点可以进行新增和修改或删除;
    • 留言板管理:用户信息的查看和删除管理;
    • 通过照片管理:前台页面显示点圆图;

    环境需要

    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项目:否;

    技术栈

    1. 后端:Spring+SpringMVC+Mybatis
    2. 前端:JSP+CSS+JavaScript+jQuery

    使用说明

    1. 使用Navicat或者其它工具,在mysql中创建对应名称的数据库,并导入项目的sql文件;
    2. 使用IDEA/Eclipse/MyEclipse导入项目,Eclipse/MyEclipse导入时,若为maven项目请选择maven;
    若为maven项目,导入成功后请执行maven clean;maven install命令,然后运行;
    3. 将项目中springmvc-servlet.xml配置文件中的数据库配置改为自己的配置;
    4. 运行项目,在浏览器中输入http://localhost:8080/ 登录

    运行截图

     

     用户管理控制层:

    1. package com.houserss.controller;
    2. import javax.servlet.http.HttpSession;
    3. import org.apache.commons.lang3.StringUtils;
    4. import org.springframework.beans.factory.annotation.Autowired;
    5. import org.springframework.stereotype.Controller;
    6. import org.springframework.web.bind.annotation.RequestMapping;
    7. import org.springframework.web.bind.annotation.RequestMethod;
    8. import org.springframework.web.bind.annotation.RequestParam;
    9. import org.springframework.web.bind.annotation.ResponseBody;
    10. import com.houserss.common.Const;
    11. import com.houserss.common.Const.Role;
    12. import com.houserss.common.ServerResponse;
    13. import com.houserss.pojo.User;
    14. import com.houserss.service.IUserService;
    15. import com.houserss.service.impl.UserServiceImpl;
    16. import com.houserss.util.MD5Util;
    17. import com.houserss.util.TimeUtils;
    18. import com.houserss.vo.DeleteHouseVo;
    19. import com.houserss.vo.PageInfoVo;
    20. /**
    21. * Created by admin
    22. */
    23. @Controller
    24. @RequestMapping("/user/")
    25. public class UserController {
    26. @Autowired
    27. private IUserService iUserService;
    28. /**
    29. * 用户登录
    30. * @param username
    31. * @param password
    32. * @param session
    33. * @return
    34. */
    35. @RequestMapping(value = "login.do",method = RequestMethod.POST)
    36. @ResponseBody
    37. public ServerResponse<User> login(User user,String uvcode, HttpSession session){
    38. String code = (String)session.getAttribute("validationCode");
    39. if(StringUtils.isNotBlank(code)) {
    40. if(!code.equalsIgnoreCase(uvcode)) {
    41. return ServerResponse.createByErrorMessage("验证码不正确");
    42. }
    43. }
    44. ServerResponse<User> response = iUserService.login(user.getUsername(),user.getPassword());
    45. if(response.isSuccess()){
    46. session.setAttribute(Const.CURRENT_USER,response.getData());
    47. }
    48. return response;
    49. }
    50. }

    管理员管理控制层:

    1. package com.sxl.controller.admin;
    2. import java.util.List;
    3. import java.util.Map;
    4. import javax.servlet.http.HttpServletRequest;
    5. import org.springframework.http.ResponseEntity;
    6. import org.springframework.stereotype.Controller;
    7. import org.springframework.ui.Model;
    8. import org.springframework.web.bind.annotation.RequestMapping;
    9. import com.sxl.controller.MyController;
    10. @Controller("adminController")
    11. @RequestMapping(value = "/admin")
    12. public class AdminController extends MyController {
    13. @RequestMapping(value = "/index")
    14. public String frame(Model model, HttpServletRequest request)throws Exception {
    15. return "/admin/index";
    16. }
    17. @RequestMapping(value = "/main")
    18. public String main(Model model, HttpServletRequest request)throws Exception {
    19. return "/admin/main";
    20. }
    21. @RequestMapping(value = "/tj1")
    22. public String tj1(Model model, HttpServletRequest request)throws Exception {
    23. String sql="select DATE_FORMAT(insertDate,'%Y-%m-%d') dates,sum(allPrice) price from t_order order by DATE_FORMAT(insertDate,'%Y-%m-%d') desc";
    24. List<Map> list = db.queryForList(sql);
    25. model.addAttribute("list", list);
    26. System.out.println(list);
    27. return "/admin/tj/tj1";
    28. }
    29. @RequestMapping(value = "/password")
    30. public String password(Model model, HttpServletRequest request)throws Exception {
    31. return "/admin/password";
    32. }
    33. @RequestMapping(value = "/changePassword")
    34. public ResponseEntity<String> loginSave(Model model,HttpServletRequest request,String oldPassword,String newPassword) throws Exception {
    35. Map admin = getAdmin(request);
    36. if(oldPassword.equals(admin.get("password").toString())){
    37. String sql="update t_admin set password=? where id=?";
    38. db.update(sql, new Object[]{newPassword,admin.get("id")});
    39. return renderData(true,"1",null);
    40. }else{
    41. return renderData(false,"1",null);
    42. }
    43. }
    44. }

    修改密码业务逻辑:

    1. package com.sxl.controller.admin;
    2. import java.util.Map;
    3. import javax.servlet.http.HttpServletRequest;
    4. import org.springframework.http.ResponseEntity;
    5. import org.springframework.stereotype.Controller;
    6. import org.springframework.ui.Model;
    7. import org.springframework.web.bind.annotation.RequestMapping;
    8. import com.sxl.controller.MyController;
    9. @Controller("userController")
    10. @RequestMapping(value = "/user")
    11. public class UserController extends MyController {
    12. @RequestMapping(value = "/index")
    13. public String frame(Model model, HttpServletRequest request)throws Exception {
    14. return "/user/index";
    15. }
    16. @RequestMapping(value = "/main")
    17. public String main(Model model, HttpServletRequest request)throws Exception {
    18. return "/user/main";
    19. }
    20. @RequestMapping(value = "/password")
    21. public String password(Model model, HttpServletRequest request)throws Exception {
    22. return "/user/password";
    23. }
    24. @RequestMapping(value = "/changePassword")
    25. public ResponseEntity<String> loginSave(Model model,HttpServletRequest request,String oldPassword,String newPassword) throws Exception {
    26. Map user = getUser(request);
    27. if(oldPassword.equals(user.get("password").toString())){
    28. String sql="update t_user set password=? where id=?";
    29. db.update(sql, new Object[]{newPassword,user.get("id")});
    30. return renderData(true,"1",null);
    31. }else{
    32. return renderData(false,"1",null);
    33. }
    34. }
    35. @RequestMapping(value = "/mine")
    36. public String mine(Model model, HttpServletRequest request)throws Exception {
    37. Map user =getUser(request);Map map = db.queryForMap("select * from t_user where id=?",new Object[]{user.get("id")});model.addAttribute("map", map); return "/user/mine";
    38. }
    39. @RequestMapping(value = "/mineSave")
    40. public ResponseEntity<String> mineSave(Model model,HttpServletRequest request,Long id
    41. ,String username,String password,String name,String gh,String mobile) throws Exception{
    42. int result = 0;
    43. String sql="update t_user set name=?,gh=?,mobile=? where id=?";
    44. result = db.update(sql, new Object[]{name,gh,mobile,id});
    45. if(result==1){
    46. return renderData(true,"操作成功",null);
    47. }else{
    48. return renderData(false,"操作失败",null);
    49. }
    50. }
    51. }

    通用管理模块:

    1. package com.sxl.controller;
    2. import java.nio.charset.Charset;
    3. import java.util.Locale;
    4. import java.util.ResourceBundle;
    5. import javax.servlet.http.HttpServletRequest;
    6. import org.apache.commons.lang.StringUtils;
    7. import org.springframework.beans.factory.annotation.Autowired;
    8. import org.springframework.http.HttpHeaders;
    9. import org.springframework.http.HttpStatus;
    10. import org.springframework.http.MediaType;
    11. import org.springframework.http.ResponseEntity;
    12. import com.sxl.util.JacksonJsonUtil;
    13. import com.sxl.util.StringUtil;
    14. import com.sxl.util.SystemProperties;
    15. public class BaseController {
    16. public static final Long EXPIRES_IN = 1000 * 3600 * 24 * 1L;// 1天
    17. @Autowired
    18. private SystemProperties systemProperties;
    19. /**
    20. * 获得配置文件内容
    21. */
    22. public String getConfig(String key) {
    23. return systemProperties.getProperties(key);
    24. }
    25. /**
    26. * 返回服务器地址 like http://192.168.1.1:8441/UUBean/
    27. */
    28. public String getHostUrl(HttpServletRequest request) {
    29. String hostName = request.getServerName();
    30. Integer hostPort = request.getServerPort();
    31. String path = request.getContextPath();
    32. if (hostPort == 80) {
    33. return "http://" + hostName + path + "/";
    34. } else {
    35. return "http://" + hostName + ":" + hostPort + path + "/";
    36. }
    37. }
    38. /***
    39. * 获取当前的website路径 String
    40. */
    41. public static String getWebSite(HttpServletRequest request) {
    42. String returnUrl = request.getScheme() + "://"
    43. + request.getServerName();
    44. if (request.getServerPort() != 80) {
    45. returnUrl += ":" + request.getServerPort();
    46. }
    47. returnUrl += request.getContextPath();
    48. return returnUrl;
    49. }
    50. /**
    51. * 初始化HTTP头.
    52. *
    53. * @return HttpHeaders
    54. */
    55. public HttpHeaders initHttpHeaders() {
    56. HttpHeaders headers = new HttpHeaders();
    57. MediaType mediaType = new MediaType("text", "html",
    58. Charset.forName("utf-8"));
    59. headers.setContentType(mediaType);
    60. return headers;
    61. }
    62. /**
    63. * 返回 信息数据
    64. *
    65. * @param status
    66. * @param msg
    67. * @return
    68. */
    69. public ResponseEntity<String> renderMsg(Boolean status, String msg) {
    70. if (StringUtils.isEmpty(msg)) {
    71. msg = "";
    72. }
    73. String str = "{\"status\":\"" + status + "\",\"msg\":\"" + msg + "\"}";
    74. ResponseEntity<String> responseEntity = new ResponseEntity<String>(str,
    75. initHttpHeaders(), HttpStatus.OK);
    76. return responseEntity;
    77. }
    78. /**
    79. * 返回obj数据
    80. *
    81. * @param status
    82. * @param msg
    83. * @param obj
    84. * @return
    85. */
    86. public ResponseEntity<String> renderData(Boolean status, String msg,
    87. Object obj) {
    88. if (StringUtils.isEmpty(msg)) {
    89. msg = "";
    90. }
    91. StringBuffer sb = new StringBuffer();
    92. sb.append("{");
    93. sb.append("\"status\":\"" + status + "\",\"msg\":\"" + msg + "\",");
    94. sb.append("\"data\":" + JacksonJsonUtil.toJson(obj) + "");
    95. sb.append("}");
    96. ResponseEntity<String> responseEntity = new ResponseEntity<String>(
    97. sb.toString(), initHttpHeaders(), HttpStatus.OK);
    98. return responseEntity;
    99. }
    100. /***
    101. * 获取IP(如果是多级代理,则得到的是一串IP值)
    102. */
    103. public static String getIpAddr(HttpServletRequest request) {
    104. String ip = request.getHeader("x-forwarded-for");
    105. if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
    106. ip = request.getHeader("Proxy-Client-IP");
    107. }
    108. if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
    109. ip = request.getHeader("WL-Proxy-Client-IP");
    110. }
    111. if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
    112. ip = request.getRemoteAddr();
    113. }
    114. if (ip != null && ip.length() > 0) {
    115. String[] ips = ip.split(",");
    116. for (int i = 0; i < ips.length; i++) {
    117. if (!"unknown".equalsIgnoreCase(ips[i])) {
    118. ip = ips[i];
    119. break;
    120. }
    121. }
    122. }
    123. return ip;
    124. }
    125. /**
    126. * 国际化获得语言内容
    127. *
    128. * @param key
    129. * 语言key
    130. * @param args
    131. * @param argsSplit
    132. * @param defaultMessage
    133. * @param locale
    134. * @return
    135. */
    136. public static String getLanguage(String key, String args, String argsSplit,
    137. String defaultMessage, String locale) {
    138. String language = "zh";
    139. String contry = "cn";
    140. String returnValue = defaultMessage;
    141. if (!StringUtil.isEmpty(locale)) {
    142. try {
    143. String[] localeArray = locale.split("_");
    144. language = localeArray[0];
    145. contry = localeArray[1];
    146. } catch (Exception e) {
    147. }
    148. }
    149. try {
    150. ResourceBundle resource = ResourceBundle.getBundle("lang.resource",
    151. new Locale(language, contry));
    152. returnValue = resource.getString(key);
    153. if (!StringUtil.isEmpty(args)) {
    154. String[] argsArray = args.split(argsSplit);
    155. for (int i = 0; i < argsArray.length; i++) {
    156. returnValue = returnValue.replace("{" + i + "}",
    157. argsArray[i]);
    158. }
    159. }
    160. } catch (Exception e) {
    161. }
    162. return returnValue;
    163. }
    164. }

    源码获取:
    大家点赞、收藏、关注、评论啦 、查看👇🏻👇🏻👇🏻QQ号获取联系方式👇🏻👇🏻👇🏻

    打卡 文章 更新 254/365天

    精彩专栏推荐订阅:下方专栏👇🏻👇🏻👇🏻👇🏻

    💪时至今日,站长仍为程序员,从14年大学开始代做毕设/课设,希望能帮助更多的同学💪

  • 相关阅读:
    KMP算法 → 计算next数组
    Python调用ChatGPT API使用国内中转key 修改接口教程
    初识C++
    保姆级微服务部署教程
    第八章 Linux文件系统权限
    又是把Java基础知识学废的一天,new 一个对象数组,操作时报空指针异常
    EasyCVR视频播放一段时间后不能播放,重启又可以正常播放是什么原因?
    操作系统的“冷板凳”要坐多久?万字长文解读16年开源老兵的坚持
    【Torch笔记】DataLoader与Dataset
    XUST——Kcsoftware Part3 题目题解
  • 原文地址:https://blog.csdn.net/qq_31293575/article/details/125434874