• Java项目:JSP小说网


    作者主页:夜未央5788

     简介:Java领域优质创作者、Java项目、学习资料、技术互助

    文末获取源码

    项目介绍

    项目主要包括管理员与用户两种角色;
    管理员角色包含以下功能:管理员登录,主页面,分类查看,修改个人信息,上传小说,查看小说,删除小说,评论顶收藏小说等功能。 
     

    用户角色包含以下功能:用户注册,用户登录,查看销售,查看小说,发布小说,搜索小说,查看个人信息等功能。

    环境需要

    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

    运行截图

    用户角色

     

     

     

     

     

    管理员角色

     

     

     

     

     

     

     

    相关代码 

    ChangeFiledServlet

    1. package servlets;
    2. /**
    3. *
    4. * 此类用于处理基本资料的更改
    5. *
    6. *
    7. */
    8. import java.io.IOException;
    9. import java.io.PrintWriter;
    10. import javax.servlet.ServletException;
    11. import javax.servlet.http.HttpServlet;
    12. import javax.servlet.http.HttpServletRequest;
    13. import javax.servlet.http.HttpServletResponse;
    14. import javax.servlet.http.HttpSession;
    15. import bean.User;
    16. import dao.UserDao;
    17. @SuppressWarnings("serial")
    18. public class ChangeFiledServlet extends HttpServlet{
    19. @Override
    20. protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    21. }
    22. @Override
    23. protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    24. req.setCharacterEncoding("utf-8");
    25. resp.setContentType("text/plain;charset=utf-8");
    26. PrintWriter out=resp.getWriter();
    27. String type=req.getParameter("type");
    28. String value=req.getParameter("value");
    29. UserDao ud=new UserDao();
    30. HttpSession session=req.getSession();
    31. if(type==null&&value==null)return;
    32. if(type.equals("changeusername")){
    33. User user=ud.getUser(value);
    34. if(user==null){
    35. User us=(User)session.getAttribute("user");
    36. if(us==null){
    37. out.print("{\"state\":1}"); //session 过期
    38. }else{
    39. us.setUser_name(value);
    40. ud.update(us);
    41. out.print("{\"state\":0}");//成功
    42. }
    43. }else{
    44. out.print("{\"state\":2}"); //用户已存在
    45. }
    46. }else if(type.equals("changenickname")){
    47. User us=(User)session.getAttribute("user");
    48. if(us==null){
    49. out.print("{\"state\":1}"); //session 过期
    50. }else{
    51. us.setNickname(value);
    52. ud.update(us);
    53. out.print("{\"state\":0}");//成功
    54. }
    55. }else if(type.equals("setsex")){
    56. User us=(User)session.getAttribute("user");
    57. if(us==null){
    58. out.print("{\"state\":1}"); //session 过期
    59. }else{
    60. us.setSex(value);
    61. ud.update(us);
    62. out.print("{\"state\":0}");//成功
    63. }
    64. }else if(type.equals("setbirthday")){
    65. User us=(User)session.getAttribute("user");
    66. if(us==null){
    67. out.print("{\"state\":1}"); //session 过期
    68. }else{
    69. us.setBirthday(value);
    70. ud.update(us);
    71. out.print("{\"state\":0}");//成功
    72. }
    73. }else if(type.equals("changeemail")){
    74. User us=(User)session.getAttribute("user");
    75. if(us==null){
    76. out.print("{\"state\":1}"); //session 过期
    77. }else{
    78. us.setEmail(value);;
    79. ud.update(us);
    80. out.print("{\"state\":0}");//成功
    81. }
    82. }else if(type.equals("changepassword")){
    83. User us=(User)session.getAttribute("user");
    84. if(us==null){
    85. out.print("{\"state\":1}"); //session 过期
    86. }else{
    87. String[] v=value.split(",");
    88. String old=v[0];
    89. String New=v[1];
    90. if(us.getPassword().equals(old)){
    91. us.setPassword(New);
    92. ud.update(us);
    93. out.print("{\"state\":0}");//成功
    94. }else{
    95. out.print("{\"state\":2}");//密码输入错误
    96. }
    97. }
    98. }
    99. }
    100. }

    GetUserDetailServlet

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

    HandleServlet

    1. package servlets;
    2. import java.io.IOException;
    3. import java.io.PrintWriter;
    4. import java.text.SimpleDateFormat;
    5. import java.util.ArrayList;
    6. import java.util.Date;
    7. import java.util.List;
    8. import javax.servlet.ServletException;
    9. import javax.servlet.http.HttpServlet;
    10. import javax.servlet.http.HttpServletRequest;
    11. import javax.servlet.http.HttpServletResponse;
    12. import javax.servlet.http.HttpSession;
    13. import bean.Collection;
    14. import bean.Comment;
    15. import bean.Post;
    16. import bean.User;
    17. import dao.CollectionDao;
    18. import dao.CommentDao;
    19. import dao.PostDao;
    20. /**
    21. *
    22. *
    23. * 此类用于处理用户点赞,收藏,顶贴
    24. * @author acer
    25. *
    26. */
    27. @SuppressWarnings("serial")
    28. public class HandleServlet extends HttpServlet{
    29. @Override
    30. protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    31. }
    32. @SuppressWarnings("unchecked")
    33. @Override
    34. protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    35. req.setCharacterEncoding("utf-8");
    36. resp.setContentType("text/plain;charset=utf-8");
    37. PrintWriter out=resp.getWriter();
    38. String type=req.getParameter("type");
    39. HttpSession session=req.getSession();
    40. User user=(User)session.getAttribute("user");
    41. if(user==null){
    42. out.print("session");
    43. return;
    44. }
    45. if(type.equals("agree")){
    46. String cid=req.getParameter("cid");
    47. List agree=(List) session.getAttribute("agree");
    48. int comment_id=Integer.parseInt(cid);
    49. if(agree==null){
    50. CommentDao cd=new CommentDao();
    51. Comment c=cd.getCommentById(comment_id);
    52. c.setAgree(c.getAgree()+1);
    53. cd.update(c);
    54. agree=new ArrayList();
    55. session.setAttribute("agree",agree);
    56. agree.add(c.getComment_id());
    57. out.print(c.getAgree());
    58. return;
    59. }
    60. if(agree.size()==0){
    61. CommentDao cd=new CommentDao();
    62. Comment c=cd.getCommentById(comment_id);
    63. c.setAgree(c.getAgree()+1);
    64. cd.update(c);
    65. agree.add(comment_id);
    66. out.print(c.getAgree());
    67. }else{
    68. boolean isAgain=false;
    69. for(Integer i:agree){
    70. if(i==comment_id){
    71. isAgain=true;
    72. break;
    73. }else {
    74. continue;
    75. }
    76. }
    77. if(isAgain){
    78. out.print("agree");
    79. return;
    80. }
    81. CommentDao cd=new CommentDao();
    82. Comment c=cd.getCommentById(comment_id);
    83. c.setAgree(c.getAgree()+1);
    84. cd.update(c);
    85. agree.add(comment_id);
    86. out.print(c.getAgree());
    87. return;
    88. }
    89. }else if(type.equals("collection")){
    90. int pid=Integer.parseInt(req.getParameter("pid"));
    91. CollectionDao cld=new CollectionDao();
    92. List cs=cld.getCollectionByUserId(user.getUser_id());
    93. boolean isAgain=false;
    94. if(cs.size()!=0){
    95. for(Collection c:cs){
    96. if(c.getPost_id()==pid){
    97. isAgain=true;
    98. break;
    99. }else{
    100. continue;
    101. }
    102. }
    103. }
    104. if(isAgain){
    105. out.print("again");
    106. return;
    107. }
    108. Collection c=new Collection();
    109. c.setPost_id(pid);
    110. c.setUser_id(user.getUser_id());
    111. Date now=new Date();
    112. SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm");
    113. String time=sdf.format(now);
    114. c.setTime(time);
    115. cld.insert(c);
    116. out.print("ok");
    117. return;
    118. }else if(type.equals("hot")){
    119. String pid=req.getParameter("pid");
    120. int post_id=Integer.parseInt(pid);
    121. List hot=(List)session.getAttribute("hot");
    122. if(hot==null){
    123. PostDao pd=new PostDao();
    124. Post p=pd.getPost(post_id);
    125. p.setHot(p.getHot()+1);
    126. pd.update(p);
    127. hot=new ArrayList();
    128. hot.add(post_id);
    129. session.setAttribute("hot", hot);
    130. out.print("ok");
    131. return;
    132. }else if(hot.size()==0){
    133. PostDao pd=new PostDao();
    134. Post p=pd.getPost(post_id);
    135. p.setHot(p.getHot()+1);
    136. pd.update(p);
    137. hot.add(post_id);
    138. out.print("ok");
    139. }else{
    140. boolean isAgain=false;
    141. for(Integer i:hot){
    142. if(i==post_id){
    143. isAgain=true;
    144. break;
    145. }else {
    146. continue;
    147. }
    148. }
    149. if(isAgain){
    150. out.print("again");
    151. return;
    152. }
    153. PostDao pd=new PostDao();
    154. Post p=pd.getPost(post_id);
    155. p.setHot(p.getHot()+1);
    156. pd.update(p);
    157. hot.add(post_id);
    158. out.print("ok");
    159. return;
    160. }
    161. }
    162. }
    163. }

    如果也想学习本系统,下面领取。关注并回复:115jsp

  • 相关阅读:
    在 Linux 中配置 SSH 连接的加密算法
    Java基础篇 | Java8流式编程
    教你制作微信公众号天气推送服务
    科比,老大1000天
    CentOS7和CentOS8 Asterisk 20.0.0 简单图形化界面8--PJSIP的环境NAT设置
    linux环境下安装jdk1.8
    Spring MVC 四:Context层级
    .NET5.0和Quartz.NET开发的极简任务调度平台
    linux中的交互式进程查看命令htop
    mybatis执行sql流程
  • 原文地址:https://blog.csdn.net/hanyunlong1989/article/details/126913808