• Java项目:小说阅读管理系统(java+JSP+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项目:否

    技术栈

    1. 后端:servlet
    2. 前端:JSP+css+javascript+bootstrap+jQuery

    使用说明

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

     

     

     

     

     

    登录管理控制层: 

    1. @SuppressWarnings("serial")
    2. public class LoginServlet extends HttpServlet{
    3. @Override
    4. protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    5. }
    6. @Override
    7. protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    8. resp.setContentType("text/plain;charset=utf-8");
    9. req.setCharacterEncoding("utf-8");
    10. PrintWriter out=resp.getWriter();
    11. String username=req.getParameter("username");
    12. String password=req.getParameter("password");
    13. HttpSession session=req.getSession();
    14. if(username==null||password==null){
    15. return;
    16. }
    17. UserDao ud=new UserDao();
    18. User user=ud.getUser(username);
    19. if(user!=null){
    20. if(user.getPassword().equals(password)){
    21. out.print("{\"state\":0}");
    22. session.setAttribute("user", user);
    23. out.close();
    24. }else{
    25. out.print("{\"state\":2}");
    26. out.close();
    27. }
    28. }else{
    29. out.print("{\"state\":1}");
    30. out.close();
    31. }
    32. }
    33. }

    用户信息管理控制层:

    1. @SuppressWarnings("serial")
    2. public class GetUserDetailServlet extends HttpServlet{
    3. @SuppressWarnings("unused")
    4. @Override
    5. protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    6. req.setCharacterEncoding("utf-8");
    7. resp.setContentType("text/plain;charset=utf-8");
    8. String type=req.getParameter("type");
    9. String uid=req.getParameter("uid");
    10. int user_id=0;
    11. if(uid!=null){
    12. user_id=Integer.parseInt(uid);
    13. }
    14. PrintWriter out=resp.getWriter();
    15. if(type==null)return;
    16. HttpSession session=req.getSession();
    17. User user=(User)session.getAttribute("user");
    18. if(user==null){
    19. return;
    20. }
    21. boolean isSmall=false;
    22. if(user_id==user.getUser_id())
    23. isSmall=true;
    24. if(type.equals("getuserpost")){
    25. UserDao ud=new UserDao();
    26. User u=ud.getUser(user_id);//当前浏览的用户
    27. if(u==null)return;
    28. PostDao pd=new PostDao();
    29. List<Post> ps=pd.getPosts(u.getUser_id());//用户发表过的帖子
    30. JSONArray jsonArray=new JSONArray();
    31. /*time
    32. * pid
    33. * title
    34. * isSamll*/
    35. for(Post p:ps){
    36. JSONObject json=new JSONObject();
    37. json.put("time", p.getPost_time());
    38. json.put("pid", p.getPost_id());
    39. json.put("title", p.getTitle());
    40. if(isSmall){
    41. json.put("isSmall", "true");
    42. }else{
    43. json.put("isSmall", "false");
    44. }
    45. jsonArray.put(json);
    46. }
    47. out.print(jsonArray.toString());
    48. }else if(type.equals("delpost")){
    49. String pid=req.getParameter("pid");
    50. if(pid==null)return;
    51. int post_id=Integer.parseInt(pid);
    52. PostDao pd=new PostDao();
    53. Post p=pd.getPost(post_id);
    54. if(p==null)return;
    55. pd.delPost(post_id);
    56. CollectionDao cld=new CollectionDao();
    57. cld.delCollectionByPostId(post_id);
    58. CommentDao cd=new CommentDao();
    59. out.print("ok");
    60. }else if(type.equals("delcollection")){
    61. String clid=req.getParameter("clid");
    62. if(clid==null)return;
    63. int cl_id=Integer.parseInt(clid);
    64. CollectionDao cld=new CollectionDao();
    65. cld.delCollectionById(cl_id);
    66. out.print("ok");
    67. return;
    68. }else if(type.equals("getusercollection")){
    69. if(uid==null){return;}
    70. CollectionDao cld=new CollectionDao();
    71. List<Collection> cls=cld.getCollectionByUserId(user_id);
    72. if(cls.size()==0)return;
    73. PostDao pd=new PostDao();
    74. UserDao ud=new UserDao();
    75. JSONArray jsonArray=new JSONArray();
    76. for(Collection c:cls){
    77. Post p=pd.getPost(c.getPost_id());
    78. int uuid=pd.getUserIdByPostId(p.getPost_id());
    79. User u=ud.getUser(uuid);
    80. JSONObject json=new JSONObject();
    81. /*time
    82. * cl_id
    83. * pid
    84. * title
    85. * isSamll
    86. * uid
    87. * unickname
    88. * pid time tile isSmall
    89. */
    90. json.put("cl_id",c.getCollection_id());
    91. json.put("pid", p.getPost_id());
    92. json.put("title", p.getTitle());
    93. json.put("time", c.getTime());
    94. json.put("uid",u.getUser_id());
    95. json.put("unickname", u.getNickname());
    96. if(isSmall){
    97. json.put("isSmall", "true");
    98. }else{
    99. json.put("isSmall", "false");
    100. }
    101. jsonArray.put(json);
    102. }
    103. out.print(jsonArray.toString());
    104. }else if(type.equals("getusercomment")){
    105. if(uid==null){return;}
    106. CommentDao cd=new CommentDao();
    107. List<Comment> cs=cd.getCommentByUserId(user_id);
    108. JSONArray jsonArray=new JSONArray();
    109. for(Comment c:cs){
    110. PostDao pd=new PostDao();
    111. String isExist="false";
    112. Post p=pd.getPost(c.getPost_id()); //发表的帖子
    113. JSONObject json=new JSONObject();
    114. if(p!=null){
    115. isExist="true";
    116. UserDao ud=new UserDao();
    117. User u=ud.getUser(p.getUser_id()); //创建人
    118. json.put("uid", u.getUser_id());
    119. json.put("title",p.getTitle());
    120. json.put("unickname",u.getNickname());
    121. json.put("pid",p.getPost_id());
    122. }
    123. json.put("cid", c.getComment_id());
    124. json.put("time",c.getTime());
    125. if(isSmall){
    126. json.put("isSmall", "true");
    127. }else{
    128. json.put("isSmall", "false");
    129. }
    130. json.put("content", c.getContent());
    131. json.put("isExist", isExist);
    132. jsonArray.put(json);
    133. }
    134. out.print(jsonArray.toString());
    135. /*cid time isSmall content uid title unickname pid isExist*/
    136. }else if(type.equals("delcomment")){
    137. String cid=req.getParameter("cid");
    138. if(cid==null)return;
    139. int comment_id=Integer.parseInt(cid);
    140. CommentDao cd=new CommentDao();
    141. cd.delCommentById(comment_id);
    142. out.print("ok");
    143. }
    144. }
    145. }

    评论管理控制层: 

    1. //评论相关
    2. @SuppressWarnings("serial")
    3. public class CommentServlet extends HttpServlet{
    4. @Override
    5. protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    6. req.setCharacterEncoding("utf-8");
    7. resp.setContentType("text/html;charset=utf-8");
    8. String type=req.getParameter("type");
    9. String content=req.getParameter("content");
    10. String pid=req.getParameter("pid");
    11. PrintWriter out=resp.getWriter();
    12. if(type==null||content==null||pid==null){
    13. return;
    14. }
    15. HttpSession session=req.getSession();
    16. User user=(User)session.getAttribute("user");
    17. if(user==null){
    18. out.print("<script type='text/javascript'>"
    19. + "window.location.href='/jsp_xiaoshuo_site/index.jsp'"
    20. + "</script>");
    21. return;
    22. }
    23. int post_id=Integer.parseInt(pid);
    24. Comment com=new Comment();
    25. com.setContent(content);
    26. com.setPost_id(post_id);
    27. com.setUser_id(user.getUser_id());
    28. Date now=new Date();
    29. SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm");
    30. String time=sdf.format(now);
    31. com.setTime(time);
    32. CommentDao cd=new CommentDao();
    33. cd.insert(com);
    34. out.print("<script type='text/javascript'>"
    35. + "window.location.href='/jsp_xiaoshuo_site/jsp/postdetail.jsp?pid="+pid+"'"
    36. + "</script>");
    37. }
    38. @Override
    39. protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    40. }
    41. }

    源码获取:俺的博客首页 "资源" 里下载!

  • 相关阅读:
    MYSQL存储引擎和索引
    【数据库】组合查询 UNION
    .NET周刊【1月第2期 2024-01-21】
    十分钟搞懂机器学习中的余弦相似性
    Java集合之ArrayList与LinkedList
    保腿还是保命,这是个问题
    sessionStorage / localStorage / cookie 存储的都是字符串类型
    Spring Boot中JSON的数据结构和交互讲解以及实战(超详细 附源码)
    实验二:数据类型、运算符和表达式——桂林航天工业学院
    企业工程项目管理系统源码(三控:进度组织、质量安全、预算资金成本、二平台:招采、设计管理)
  • 原文地址:https://blog.csdn.net/m0_66863468/article/details/125466592