From 21a5f6f085a7bb3bdad5cf697bd667c286643c91 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=83=91=E7=8E=89=E5=BC=BA?= <2652201678@qq.com> Date: Wed, 1 Mar 2023 21:12:15 +0800 Subject: [PATCH 1/4] =?UTF-8?q?=E7=94=A8=E6=88=B7=E7=BC=96=E8=BE=91?= =?UTF-8?q?=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../f9a4aa96-34a3-4893-85e5-538605dcfc4e.xml | 87 +++++++++++++++++-- .idea/workspace.xml | 51 ++++++++++- pom.xml | 6 +- .../java/cn/zyq/vesionone/dao/UserDAO.java | 32 +++++++ .../cn/zyq/vesionone/filter/CheckFilter.java | 52 +++++++++++ .../java/cn/zyq/vesionone/pojo/UserBlog.java | 75 ++++++++++++++++ .../zyq/vesionone/pojo/UserBlogContext.java | 34 ++++++++ .../cn/zyq/vesionone/service/UserService.java | 3 + .../service/impl/UserServiceImpl.java | 9 ++ .../java/cn/zyq/vesionone/utils/Utils.java | 28 ++++++ .../cn/zyq/vesionone/web/EditBlogServlet.java | 57 ++++++++++++ .../cn/zyq/vesionone/web/LogOffServlet.java | 31 +++++++ src/main/resources/development_process.txt | 12 ++- src/main/webapp/List.html | 36 +++++++- src/main/webapp/betterUIForLR.html | 2 +- src/main/webapp/details.html | 25 +++++- src/main/webapp/edit.html | 69 +++++++++++++-- src/test/java/Test.java | 15 ++++ 18 files changed, 595 insertions(+), 29 deletions(-) create mode 100644 src/main/java/cn/zyq/vesionone/filter/CheckFilter.java create mode 100644 src/main/java/cn/zyq/vesionone/pojo/UserBlog.java create mode 100644 src/main/java/cn/zyq/vesionone/pojo/UserBlogContext.java create mode 100644 src/main/java/cn/zyq/vesionone/utils/Utils.java create mode 100644 src/main/java/cn/zyq/vesionone/web/EditBlogServlet.java create mode 100644 src/main/java/cn/zyq/vesionone/web/LogOffServlet.java create mode 100644 src/test/java/Test.java diff --git a/.idea/dataSources/f9a4aa96-34a3-4893-85e5-538605dcfc4e.xml b/.idea/dataSources/f9a4aa96-34a3-4893-85e5-538605dcfc4e.xml index fa533b1..695fe69 100644 --- a/.idea/dataSources/f9a4aa96-34a3-4893-85e5-538605dcfc4e.xml +++ b/.idea/dataSources/f9a4aa96-34a3-4893-85e5-538605dcfc4e.xml @@ -20,45 +20,116 @@ InnoDB utf8_general_ci - + + InnoDB + utf8_general_ci +
+ + InnoDB + utf8_general_ci +
+ 3 int(11)|0s 1 1 - + varchar(20)|0s 1 2 - + varchar(20)|0s 1 3 - + varchar(20)|0s '123456' 1 4 - + userID btree 1 - + email btree 1 - + 1 1 PRIMARY - + email + + int(11)|0s + 1 + 1 + + + varchar(50)|0s + 1 + 2 + + + datetime|0s + 3 + + + char(255)|0s + '详情请查看' + 1 + 4 + + + 1 + int(11)|0s + 1 + 5 + + + userID + userID + user + + + textID + btree + 1 + + + userID + btree + + + 1 + 1 + PRIMARY + + + int(11)|0s + 1 + 1 + + + text|0s + 2 + + + textID + textID + user_blog + + + textID + btree + \ No newline at end of file diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 32b045c..1e0a7d5 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -5,10 +5,24 @@ + + + + + + + + - - + + + + + + + + + + + + + + + + + + @@ -106,7 +137,12 @@ - + + + + + + 1677144154839 @@ -143,7 +179,14 @@ - diff --git a/pom.xml b/pom.xml index dce29a9..8f018d6 100644 --- a/pom.xml +++ b/pom.xml @@ -29,9 +29,9 @@ - org.junit.jupiter - junit-jupiter-api - 5.3.0-M1 + junit + junit + 4.13.2 test diff --git a/src/main/java/cn/zyq/vesionone/dao/UserDAO.java b/src/main/java/cn/zyq/vesionone/dao/UserDAO.java index 9e43194..6ad919a 100644 --- a/src/main/java/cn/zyq/vesionone/dao/UserDAO.java +++ b/src/main/java/cn/zyq/vesionone/dao/UserDAO.java @@ -1,6 +1,7 @@ package cn.zyq.vesionone.dao; import cn.zyq.vesionone.pojo.User; +import cn.zyq.vesionone.pojo.UserBlog; import java.sql.*; @@ -93,4 +94,35 @@ public class UserDAO { return user; } + public void insertBlogContext(UserBlog userBlog) throws SQLException { + + String sql1 = "INSERT INTO user_blog(userID,title,publish_date,brief_info) VALUES (?,?,?,?)"; + String sql2 = "INSERT INTO user_blog_context(context) VALUES (?)"; + + try( Connection connection = getConnection(); + PreparedStatement preparedStatement1 = connection.prepareStatement(sql1); + PreparedStatement preparedStatement2 = connection.prepareStatement(sql2);){ + // 设置?的值 + preparedStatement1.setInt(1,userBlog.getUserID()); + preparedStatement1.setString(2,userBlog.getTitle()); + preparedStatement1.setString(3,userBlog.getPublishDate()); + preparedStatement1.setString(4,userBlog.getBriefInfo()); + + preparedStatement2.setString(1,userBlog.getContext()); + +// // 有事务的前提下 +// // 在事务中的多个操作,要么都成功,要么都失败 + connection.setAutoCommit(false); + + // 执行插入操作 + preparedStatement1.execute(); + preparedStatement2.execute(); + +// // 手动提交 + connection.commit(); + + } + + } + } diff --git a/src/main/java/cn/zyq/vesionone/filter/CheckFilter.java b/src/main/java/cn/zyq/vesionone/filter/CheckFilter.java new file mode 100644 index 0000000..91d47b9 --- /dev/null +++ b/src/main/java/cn/zyq/vesionone/filter/CheckFilter.java @@ -0,0 +1,52 @@ +package cn.zyq.vesionone.filter; + +import javax.servlet.*; +import javax.servlet.annotation.*; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.servlet.http.HttpSession; +import java.io.IOException; + +@WebFilter("*.html") +public class CheckFilter extends HttpServlet implements Filter{ + + public void init(FilterConfig config) throws ServletException { + } + + public void destroy() { + } + + @Override + public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws ServletException, IOException { + // 放行前 + // 从session中获取数据 + // 1、获取session对象 + HttpServletRequest req = (HttpServletRequest) request; + HttpServletResponse resp = (HttpServletResponse) response; + HttpSession session = req.getSession(false); + +// 3.在Servlet中取得路径: +// +// (1)得到工程目录:request.getSession().getServletContext().getRealPath("") 参数可具体到包名。 +// 结果:E:/Tomcat/webapps/TEST +// (2)得到IE地址栏地址:request.getRequestURL() +// 结果:http://localhost:8080/TEST/test +// (3)得到相对地址:request.getRequestURI() +// 结果:/TEST/test + + String uri = req.getRequestURI(); + + System.out.println(uri); + + if ( session == null && !"/blog/betterUIForLR.html".equals(uri) ){ +// 重定向 + String contextPath = req.getContextPath(); + resp.sendRedirect(contextPath+"/betterUIForLR.html"); + } + + // 放行 + chain.doFilter(request, response); + // 放行后 + } +} diff --git a/src/main/java/cn/zyq/vesionone/pojo/UserBlog.java b/src/main/java/cn/zyq/vesionone/pojo/UserBlog.java new file mode 100644 index 0000000..3181832 --- /dev/null +++ b/src/main/java/cn/zyq/vesionone/pojo/UserBlog.java @@ -0,0 +1,75 @@ +package cn.zyq.vesionone.pojo; + +public class UserBlog { + + private int userID; + private String title; + private String publishDate; + private String briefInfo; + private int textID; + + private String context; + + public UserBlog() { + } + + public int getUserID() { + return userID; + } + + public void setUserID(int userID) { + this.userID = userID; + } + + public String getTitle() { + return title; + } + + public void setTitle(String title) { + this.title = title; + } + + public String getPublishDate() { + return publishDate; + } + + public void setPublishDate(String publishDate) { + this.publishDate = publishDate; + } + + public String getBriefInfo() { + return briefInfo; + } + + public void setBriefInfo(String briefInfo) { + this.briefInfo = briefInfo; + } + + public int getTextID() { + return textID; + } + + public void setTextID(int textID) { + this.textID = textID; + } + + public String getContext() { + return context; + } + + public void setContext(String context) { + this.context = context; + } + + @Override + public String toString() { + return "UserBlog{" + + "userID=" + userID + + ", title='" + title + '\'' + + ", publishDate='" + publishDate + '\'' + + ", briefInfo='" + briefInfo + '\'' + + ", textID=" + textID + + ", context='" + context + '\'' + + '}'; + } +} diff --git a/src/main/java/cn/zyq/vesionone/pojo/UserBlogContext.java b/src/main/java/cn/zyq/vesionone/pojo/UserBlogContext.java new file mode 100644 index 0000000..4d47440 --- /dev/null +++ b/src/main/java/cn/zyq/vesionone/pojo/UserBlogContext.java @@ -0,0 +1,34 @@ +package cn.zyq.vesionone.pojo; + +public class UserBlogContext { + + private int textID; + private String context; + + public UserBlogContext() { + } + + public int getTextID() { + return textID; + } + + public void setTextID(int textID) { + this.textID = textID; + } + + public String getContext() { + return context; + } + + public void setContext(String context) { + this.context = context; + } + + @Override + public String toString() { + return "UserBlogContext{" + + "textID=" + textID + + ", context='" + context + '\'' + + '}'; + } +} diff --git a/src/main/java/cn/zyq/vesionone/service/UserService.java b/src/main/java/cn/zyq/vesionone/service/UserService.java index 60ac315..5366673 100644 --- a/src/main/java/cn/zyq/vesionone/service/UserService.java +++ b/src/main/java/cn/zyq/vesionone/service/UserService.java @@ -1,6 +1,7 @@ package cn.zyq.vesionone.service; import cn.zyq.vesionone.pojo.User; +import cn.zyq.vesionone.pojo.UserBlog; public interface UserService { public void register(User user); @@ -8,4 +9,6 @@ public interface UserService { public User login(String email); public User getUserByEmailAndPassword(String email,String password); + + public void insertNewContext(UserBlog userBlog); } diff --git a/src/main/java/cn/zyq/vesionone/service/impl/UserServiceImpl.java b/src/main/java/cn/zyq/vesionone/service/impl/UserServiceImpl.java index 0c9ae93..7eee82b 100644 --- a/src/main/java/cn/zyq/vesionone/service/impl/UserServiceImpl.java +++ b/src/main/java/cn/zyq/vesionone/service/impl/UserServiceImpl.java @@ -2,6 +2,7 @@ package cn.zyq.vesionone.service.impl; import cn.zyq.vesionone.dao.UserDAO; import cn.zyq.vesionone.pojo.User; +import cn.zyq.vesionone.pojo.UserBlog; import cn.zyq.vesionone.service.UserService; import java.sql.SQLException; @@ -38,4 +39,12 @@ public class UserServiceImpl implements UserService { return user; } + public void insertNewContext(UserBlog userBlog){ + try { + userDAO.insertBlogContext(userBlog); + } catch (SQLException e) { + throw new RuntimeException(e); + } + } + } diff --git a/src/main/java/cn/zyq/vesionone/utils/Utils.java b/src/main/java/cn/zyq/vesionone/utils/Utils.java new file mode 100644 index 0000000..81eec52 --- /dev/null +++ b/src/main/java/cn/zyq/vesionone/utils/Utils.java @@ -0,0 +1,28 @@ +package cn.zyq.vesionone.utils; + +import java.text.DateFormat; +import java.text.SimpleDateFormat; +import java.util.Date; + +public class Utils { + + public static String getCurrentTime(){ + DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//注意月和小时的格式为两个大写字母 + Date date = new Date();//获得当前时间 + String currentTime = df.format(date);//将当前时间转换成特定格式的时间字符串,这样便可以插入到数据库中 + + return currentTime; + } + + public static String getBriefInfo(String context){ + String str = ""; + if ( context.length() > 100 ) + str = context.substring(0,100); + else { + str = context.substring(0,context.length()); + } + + return str; + } + +} diff --git a/src/main/java/cn/zyq/vesionone/web/EditBlogServlet.java b/src/main/java/cn/zyq/vesionone/web/EditBlogServlet.java new file mode 100644 index 0000000..4f2e46b --- /dev/null +++ b/src/main/java/cn/zyq/vesionone/web/EditBlogServlet.java @@ -0,0 +1,57 @@ +package cn.zyq.vesionone.web; + +import cn.zyq.vesionone.pojo.User; +import cn.zyq.vesionone.pojo.UserBlog; +import cn.zyq.vesionone.service.UserService; +import cn.zyq.vesionone.service.impl.UserServiceImpl; +import cn.zyq.vesionone.utils.Utils; + +import javax.servlet.*; +import javax.servlet.http.*; +import javax.servlet.annotation.*; +import java.io.IOException; +import java.text.DateFormat; +import java.text.SimpleDateFormat; +import java.util.Date; + +@WebServlet("/editBlogServlet") +public class EditBlogServlet extends HttpServlet { + private UserService userService= new UserServiceImpl(); + @Override + protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + + // 1、获取session对象 + HttpSession session = request.getSession(); + // 2、获取数据 + User loginUser = (User)session.getAttribute("user"); + + // 获取编辑页面提交的数据 + String title = request.getParameter("title"); + String category = request.getParameter("category"); + String editContext = request.getParameter("editContext"); + + // 实例化pojo + UserBlog newUserBlog = new UserBlog(); + + newUserBlog.setUserID(loginUser.getUserID()); + newUserBlog.setTitle(title); + newUserBlog.setPublishDate(Utils.getCurrentTime()); + newUserBlog.setBriefInfo(Utils.getBriefInfo(editContext)); + newUserBlog.setContext(editContext); + + + userService.insertNewContext(newUserBlog); + + + // 服务器内跳转 + request.getRequestDispatcher("/List.html").forward(request,response); +// // 重定向 +// String contextPath = request.getContextPath(); +// response.sendRedirect(contextPath+"/List.html"); + } + + @Override + protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + this.doGet(request, response); + } +} diff --git a/src/main/java/cn/zyq/vesionone/web/LogOffServlet.java b/src/main/java/cn/zyq/vesionone/web/LogOffServlet.java new file mode 100644 index 0000000..c9e6bb5 --- /dev/null +++ b/src/main/java/cn/zyq/vesionone/web/LogOffServlet.java @@ -0,0 +1,31 @@ +package cn.zyq.vesionone.web; + +import javax.servlet.*; +import javax.servlet.http.*; +import javax.servlet.annotation.*; +import java.io.IOException; + +@WebServlet("/logOffServlet") +public class LogOffServlet extends HttpServlet { + @Override + protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + //注销就是通过session对象删除保存的用户信息 + HttpSession session = request.getSession(false); + if(session != null){ + // 销毁session + session.invalidate(); + } + + +// // 服务器内跳转 +// request.getRequestDispatcher("/betterUIForLR.html").forward(request,response); + // 重定向 + String contextPath = request.getContextPath(); + response.sendRedirect(contextPath+"/betterUIForLR.html"); + } + + @Override + protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + this.doGet(request, response); + } +} diff --git a/src/main/resources/development_process.txt b/src/main/resources/development_process.txt index b250d79..d6b5e45 100644 --- a/src/main/resources/development_process.txt +++ b/src/main/resources/development_process.txt @@ -1,7 +1,15 @@ +version 1 前端界面 done 登录功能 done 注册功能 done servlet和静态页面通过session和Ajax进行数据交互 done 利用cookie实现记住登录功能 done -完善用户写博客功能 to do -完善忘记密码功能 to do +完成注销功能 done +完成忘记密码功能 done +完成户写博客功能 done +完成未登录访问或许页面拦截器 done +提交编辑但是中文乱码 to do + + + + diff --git a/src/main/webapp/List.html b/src/main/webapp/List.html index c5a4cb8..6ae4f01 100644 --- a/src/main/webapp/List.html +++ b/src/main/webapp/List.html @@ -16,7 +16,7 @@
@@ -26,7 +26,7 @@
游客
@@ -56,6 +56,38 @@ similique quaerat vel. Facere,et.

+
+

我的第一篇博客

+

2022-08-09 09:31:28

+

从今天起, 我要认真敲代码. Lorem ipsum, dolor sit amet consectetur adipisicing elit. + Cum distinctio ullam eum ut veroab laborum numquam tenetur est in dolorum a sint, assumenda adipisci + similique quaerat vel. Facere,et.

+ +
+
+

我的第二篇博客

+

2022-08-11 16:31:35

+

从今天起, 我要认真敲代码. Lorem ipsum, dolor sit amet consectetur adipisicing elit. + Cum distinctio ullam eum ut veroab laborum numquam tenetur est in dolorum a sint, assumenda adipisci + similique quaerat vel. Facere,et.

+ +
+
+

我的第一篇博客

+

2022-08-09 09:31:28

+

从今天起, 我要认真敲代码. Lorem ipsum, dolor sit amet consectetur adipisicing elit. + Cum distinctio ullam eum ut veroab laborum numquam tenetur est in dolorum a sint, assumenda adipisci + similique quaerat vel. Facere,et.

+ +
+
+

我的第二篇博客

+

2022-08-11 16:31:35

+

从今天起, 我要认真敲代码. Lorem ipsum, dolor sit amet consectetur adipisicing elit. + Cum distinctio ullam eum ut veroab laborum numquam tenetur est in dolorum a sint, assumenda adipisci + similique quaerat vel. Facere,et.

+ +
diff --git a/src/main/webapp/betterUIForLR.html b/src/main/webapp/betterUIForLR.html index 9153687..ef3a626 100644 --- a/src/main/webapp/betterUIForLR.html +++ b/src/main/webapp/betterUIForLR.html @@ -131,7 +131,7 @@ else { document.getElementById("LoginEmail").value = returnData.email; document.getElementById("LoginPassword").value = returnData.password; - document.getElementById("loginForm").submit(); + // document.getElementById("loginForm").submit(); } } ) } diff --git a/src/main/webapp/details.html b/src/main/webapp/details.html index a45e7c8..03e4549 100644 --- a/src/main/webapp/details.html +++ b/src/main/webapp/details.html @@ -16,7 +16,7 @@
@@ -24,7 +24,7 @@
-
小熊吃糖
+
小熊吃糖
@@ -63,5 +63,26 @@
+ + + + + + \ No newline at end of file diff --git a/src/main/webapp/edit.html b/src/main/webapp/edit.html index dfd51d4..765c665 100644 --- a/src/main/webapp/edit.html +++ b/src/main/webapp/edit.html @@ -17,19 +17,20 @@
- -
+
- - - + 博客标题: + 博客分类: +
+ 博客内容: +
-
+
@@ -52,5 +53,59 @@ path: "./editor.md/lib/" }); + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/test/java/Test.java b/src/test/java/Test.java new file mode 100644 index 0000000..5f9cda9 --- /dev/null +++ b/src/test/java/Test.java @@ -0,0 +1,15 @@ +import java.text.DateFormat; +import java.text.SimpleDateFormat; +import java.util.Date; + +public class Test { + + @org.junit.Test + public void m1(){ + DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//注意月和小时的格式为两个大写字母 + Date date = new Date();//获得当前时间 + String birthday = df.format(date);//将当前时间转换成特定格式的时间字符串,这样便可以插入到数据库中 + System.out.println(birthday); + } + +} -- Gitee From 651bb0f04b56b7806cee62b3973636814bd43390 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=83=91=E7=8E=89=E5=BC=BA?= <2652201678@qq.com> Date: Thu, 2 Mar 2023 17:39:35 +0800 Subject: [PATCH 2/4] =?UTF-8?q?=E5=8A=9F=E8=83=BD=E5=9F=BA=E6=9C=AC?= =?UTF-8?q?=E5=AE=8C=E5=96=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .idea/uiDesigner.xml | 124 ++++++++++++++++ .idea/webContexts.xml | 1 + .idea/workspace.xml | 38 +++-- .../java/cn/zyq/vesionone/dao/UserDAO.java | 139 ++++++++++++++++-- .../cn/zyq/vesionone/filter/CheckFilter.java | 2 +- .../cn/zyq/vesionone/service/UserService.java | 7 + .../service/impl/UserServiceImpl.java | 32 ++++ .../web/DetailBlogContextServlet.java | 42 ++++++ .../vesionone/web/DetailBlogInfoServlet.java | 39 +++++ .../cn/zyq/vesionone/web/EditBlogServlet.java | 22 ++- .../vesionone/web/LoadUserBlogsServlet.java | 46 ++++++ .../cn/zyq/vesionone/web/RedirectServlet.java | 27 ++++ src/main/resources/development_process.txt | 22 +-- src/main/webapp/List.html | 93 ++++++------ src/main/webapp/details.html | 42 +++--- src/main/webapp/edit.html | 3 +- src/main/webapp/js/utils.js | 27 ++++ 17 files changed, 594 insertions(+), 112 deletions(-) create mode 100644 .idea/uiDesigner.xml create mode 100644 src/main/java/cn/zyq/vesionone/web/DetailBlogContextServlet.java create mode 100644 src/main/java/cn/zyq/vesionone/web/DetailBlogInfoServlet.java create mode 100644 src/main/java/cn/zyq/vesionone/web/LoadUserBlogsServlet.java create mode 100644 src/main/java/cn/zyq/vesionone/web/RedirectServlet.java create mode 100644 src/main/webapp/js/utils.js diff --git a/.idea/uiDesigner.xml b/.idea/uiDesigner.xml new file mode 100644 index 0000000..2b63946 --- /dev/null +++ b/.idea/uiDesigner.xml @@ -0,0 +1,124 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/webContexts.xml b/.idea/webContexts.xml index 91eb9e8..03c0f3e 100644 --- a/.idea/webContexts.xml +++ b/.idea/webContexts.xml @@ -3,6 +3,7 @@ diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 1e0a7d5..ddf0133 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -5,22 +5,21 @@ - - - - - - - - + + + + + + + - + + - @@ -35,8 +34,8 @@ @@ -142,7 +141,10 @@ - + + + + 1677144154839 @@ -186,7 +188,14 @@ -
-
+

我的第一篇博客

2022-08-09 09:31:28

@@ -48,46 +48,7 @@ similique quaerat vel. Facere,et.

-
-

我的第二篇博客

-

2022-08-11 16:31:35

-

从今天起, 我要认真敲代码. Lorem ipsum, dolor sit amet consectetur adipisicing elit. - Cum distinctio ullam eum ut veroab laborum numquam tenetur est in dolorum a sint, assumenda adipisci - similique quaerat vel. Facere,et.

- -
-
-

我的第一篇博客

-

2022-08-09 09:31:28

-

从今天起, 我要认真敲代码. Lorem ipsum, dolor sit amet consectetur adipisicing elit. - Cum distinctio ullam eum ut veroab laborum numquam tenetur est in dolorum a sint, assumenda adipisci - similique quaerat vel. Facere,et.

- -
-
-

我的第二篇博客

-

2022-08-11 16:31:35

-

从今天起, 我要认真敲代码. Lorem ipsum, dolor sit amet consectetur adipisicing elit. - Cum distinctio ullam eum ut veroab laborum numquam tenetur est in dolorum a sint, assumenda adipisci - similique quaerat vel. Facere,et.

- -
-
-

我的第一篇博客

-

2022-08-09 09:31:28

-

从今天起, 我要认真敲代码. Lorem ipsum, dolor sit amet consectetur adipisicing elit. - Cum distinctio ullam eum ut veroab laborum numquam tenetur est in dolorum a sint, assumenda adipisci - similique quaerat vel. Facere,et.

- -
-
-

我的第二篇博客

-

2022-08-11 16:31:35

-

从今天起, 我要认真敲代码. Lorem ipsum, dolor sit amet consectetur adipisicing elit. - Cum distinctio ullam eum ut veroab laborum numquam tenetur est in dolorum a sint, assumenda adipisci - similique quaerat vel. Facere,et.

- -
+
@@ -101,15 +62,63 @@ method: "get", url:"http://localhost:8080/blog/loadUserInfoServlet", }).then(function (resp){ + // 加载 let currentLoginUser = resp.data; document.getElementById("currentUserName").innerHTML = currentLoginUser.userName; - }) + }); + + axios({ + method: "get", + url: "http://localhost:8080/blog/loadUserBlogsServlet", + }).then( function (resp){ + // 加载 + let blogs = resp.data; + let blogHtml = ""; + for ( let i = 0; i < blogs.length; i++){ + let blog = blogs[i]; + blogHtml += "\n"+ + "
" + + "

"+ blog.title +"

" + + "

"+ blog.publishDate +"

" + + "

" + blog.briefInfo + "

"+ + "
"+ + " 查看全文"+ + "
"+ + "
"+ + "

"+ + "\n"; + } + // 设置块内数据 + document.getElementById("showBlogs").innerHTML = blogHtml; + }); + + // 从新加载css 不管用 + // let link = document.createElement("link"); + // link.rel = "stylesheet"; + // // link.type = "text/css"; + // link.href = "./css/List.css"; + // document.getElementsByTagName("head")[0].appendChild(link); } + + + + + \ No newline at end of file diff --git a/src/main/webapp/details.html b/src/main/webapp/details.html index 03e4549..16040f1 100644 --- a/src/main/webapp/details.html +++ b/src/main/webapp/details.html @@ -6,6 +6,7 @@ +
@@ -14,7 +15,7 @@ 我的博客系统
@@ -40,30 +41,14 @@
-
-

我的第一篇博客

-

2022-08-09 09:31:28

-

-

- 从今天起我要好好敲代码.Lorem ipsum dolor sit amet, - consectetur adipisicing elit. Aut recusandae omnis natus ut! Autem alias ullam sit facilis ipsa dolore, - molestiae neque aperiam in a facere dolor mollitia dolorum animi. - Lorem ipsum dolor sit amet, consectetur adipisicing elit. Aut recusandae omnis natus ut! Autem alias - ullam sit facilis ipsa dolore, molestiae neque aperiam in a facere dolor mollitia dolorum animi. Lorem - ipsum dolor sit amet, consectetur adipisicing elit. - Aut recusandae omnis natus ut! Autem alias ullam sit facilis ipsa dolore, molestiae neque aperiam in a - facere dolor mollitia dolorum animi.

-

- Lorem ipsum dolor sit amet consectetur adipisicing elit. Laudantium sint accusantium, enim iste - corrupti itaque, omnis alias maiores nemo quae rerum deleniti facere officiis iure velit. - Blanditiis pariatur delectus perferendis. Lorem ipsum dolor sit amet consectetur adipisicing elit. - Laudantium sint accusantium, enim iste corrupti itaque, - omnis alias maiores nemo quae rerum deleniti facere officiis iure velit. Blanditiis pariatur delectus - perferendis.

+
+
+ + @@ -80,6 +65,21 @@ document.getElementById("currentUserName").innerHTML = currentLoginUser.userName; }) + // 请求数据 + axios({ + method: "get", + url:"http://localhost:8080/blog/detailBlogContextServlet", + }).then(function (resp){ + let returnData = resp.data; + let context = "\n" + + "

"+ returnData.title +"

" + + "

"+ returnData.publishDate +"

" + + "

" + + "

"+ returnData.context +"

" + + "

"+ + "\n"; + document.getElementById("detail_blogContext").innerHTML = context; + }) } diff --git a/src/main/webapp/edit.html b/src/main/webapp/edit.html index 765c665..2166eb1 100644 --- a/src/main/webapp/edit.html +++ b/src/main/webapp/edit.html @@ -15,7 +15,7 @@ 我的博客系统 @@ -35,6 +35,7 @@ + diff --git a/src/main/webapp/js/utils.js b/src/main/webapp/js/utils.js new file mode 100644 index 0000000..a5e27b2 --- /dev/null +++ b/src/main/webapp/js/utils.js @@ -0,0 +1,27 @@ +// import './axios-0.18.0' + +function haha(){ + alert("hhaa") +} + +function backToListDotHTML(){ + alert("jjj") + //1. 创建核心对象 + var xhttp; + if (window.XMLHttpRequest) { + xhttp = new XMLHttpRequest(); + } else { + // code for IE6, IE5 + xhttp = new ActiveXObject("Microsoft.XMLHTTP"); + } + //2. 发送请求 + xhttp.open("GET", "http://localhost:8080/blog/redirectServlet?target=List.html"); + xhttp.send(); + //3. 获取响应 + xhttp.onreadystatechange = function() { + if (this.readyState == 4 && this.status == 200) { + alert(this.responseText); + } + }; + +} -- Gitee From fc157107a8818cadd3cc630bb12c31794adf1691 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=83=91=E7=8E=89=E5=BC=BA?= <2652201678@qq.com> Date: Thu, 2 Mar 2023 21:36:03 +0800 Subject: [PATCH 3/4] =?UTF-8?q?=E5=8A=9F=E8=83=BD=E5=9F=BA=E6=9C=AC?= =?UTF-8?q?=E5=AE=8C=E5=96=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .idea/workspace.xml | 34 +++++++++---------- .../filter/SolveChineseTransFilter.java | 25 ++++++++++++++ .../web/DetailBlogContextServlet.java | 3 ++ .../vesionone/web/DetailBlogInfoServlet.java | 28 +++++++-------- src/main/webapp/List.html | 7 ++-- src/main/webapp/details.html | 6 ++-- 6 files changed, 67 insertions(+), 36 deletions(-) create mode 100644 src/main/java/cn/zyq/vesionone/filter/SolveChineseTransFilter.java diff --git a/.idea/workspace.xml b/.idea/workspace.xml index ddf0133..7068214 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -5,23 +5,12 @@
- - - - - - - + - - - - - - + + - @@ -219,7 +218,8 @@ - diff --git a/src/main/java/cn/zyq/vesionone/filter/SolveChineseTransFilter.java b/src/main/java/cn/zyq/vesionone/filter/SolveChineseTransFilter.java new file mode 100644 index 0000000..e263789 --- /dev/null +++ b/src/main/java/cn/zyq/vesionone/filter/SolveChineseTransFilter.java @@ -0,0 +1,25 @@ +package cn.zyq.vesionone.filter; + +import javax.servlet.*; +import javax.servlet.annotation.*; +import java.io.IOException; + +@WebFilter("/*") +public class SolveChineseTransFilter implements Filter { + public void init(FilterConfig config) throws ServletException { + } + + public void destroy() { + } + + @Override + public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws ServletException, IOException { + + //解决乱码: POST getReader() + //设置字符输入流的编码,设置的字符集要和页面保持一致 + request.setCharacterEncoding("UTF-8"); + + chain.doFilter(request, response); + + } +} diff --git a/src/main/java/cn/zyq/vesionone/web/DetailBlogContextServlet.java b/src/main/java/cn/zyq/vesionone/web/DetailBlogContextServlet.java index fff4e94..d25f4c1 100644 --- a/src/main/java/cn/zyq/vesionone/web/DetailBlogContextServlet.java +++ b/src/main/java/cn/zyq/vesionone/web/DetailBlogContextServlet.java @@ -17,6 +17,7 @@ public class DetailBlogContextServlet extends HttpServlet { @Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + System.out.println("/detailBlogContextServlet"); // 获取session对象 HttpSession session = request.getSession(); @@ -30,6 +31,8 @@ public class DetailBlogContextServlet extends HttpServlet { // 将对象转换为json对象 String jsonString = JSON.toJSONString(userBlog); +// System.out.println(jsonString); + //响应数据 response.setContentType("text/json;charset=utf-8"); response.getWriter().write(jsonString); diff --git a/src/main/java/cn/zyq/vesionone/web/DetailBlogInfoServlet.java b/src/main/java/cn/zyq/vesionone/web/DetailBlogInfoServlet.java index 313cd5d..ceb2976 100644 --- a/src/main/java/cn/zyq/vesionone/web/DetailBlogInfoServlet.java +++ b/src/main/java/cn/zyq/vesionone/web/DetailBlogInfoServlet.java @@ -1,11 +1,5 @@ package cn.zyq.vesionone.web; -import cn.zyq.vesionone.dao.UserDAO; -import cn.zyq.vesionone.pojo.UserBlog; -import cn.zyq.vesionone.service.UserService; -import cn.zyq.vesionone.service.impl.UserServiceImpl; -import com.alibaba.fastjson.JSON; - import javax.servlet.*; import javax.servlet.http.*; import javax.servlet.annotation.*; @@ -14,22 +8,28 @@ import java.io.IOException; @WebServlet("/detailBlogInfoServlet") public class DetailBlogInfoServlet extends HttpServlet { - - @Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { +// System.out.println("/detailBlogInfoServlet"); + // 获取session对象 - HttpSession session = request.getSession(); + HttpSession session = request.getSession(false); + +// System.out.println(session); String textID = request.getParameter("textID"); +// System.out.println(textID); // 存储数据 session.setAttribute("textID",textID); - // // 服务器内跳转 -// request.getRequestDispatcher("/betterUIForLR.html").forward(request,response); - // 重定向 - String contextPath = request.getContextPath(); - response.sendRedirect(contextPath+"/details.html"); + + response.getWriter().write("http://localhost:8080/blog/details.html"); +// // 服务器内跳转 +// request.getRequestDispatcher("/edit.html").forward(request,response); +// // 重定向 +// String contextPath = request.getContextPath(); +// System.out.println(contextPath); +// response.sendRedirect(contextPath+"/details.html"); } @Override diff --git a/src/main/webapp/List.html b/src/main/webapp/List.html index 9a1e860..9439878 100644 --- a/src/main/webapp/List.html +++ b/src/main/webapp/List.html @@ -107,13 +107,14 @@ + @@ -70,6 +71,7 @@ method: "get", url:"http://localhost:8080/blog/detailBlogContextServlet", }).then(function (resp){ + // alert("这是一个函数标点") let returnData = resp.data; let context = "\n" + "

"+ returnData.title +"

" + -- Gitee From 8fb7930a79578300449ed5105a9d220afa3700de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=83=91=E7=8E=89=E5=BC=BA?= <2652201678@qq.com> Date: Sat, 4 Mar 2023 21:23:24 +0800 Subject: [PATCH 4/4] =?UTF-8?q?=E5=BC=95=E5=85=A5=E5=BC=80=E6=BA=90?= =?UTF-8?q?=E7=9A=84markdown?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .idea/workspace.xml | 154 ++++++++++++++++-- pom.xml | 2 +- .../cn/zyq/vesionone/filter/CheckFilter.java | 4 + .../filter/SolveChineseTransFilter.java | 2 + .../cn/zyq/vesionone/web/EditBlogServlet.java | 2 +- src/main/webapp/edit.html | 16 +- 6 files changed, 161 insertions(+), 19 deletions(-) diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 7068214..591e96d 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -1,16 +1,21 @@ + + + + + - - + - - - - + + + + + + + @@ -65,7 +77,7 @@ "WebServerToolWindowFactoryState": "false", "last_opened_file_path": "D:/IntelliJ IDEA/Java_Workplace/blog/src/main/webapp/imgs", "list.type.of.created.stylesheet": "CSS", - "project.structure.last.edited": "Modules", + "project.structure.last.edited": "Artifacts", "project.structure.proportion": "0.15", "project.structure.side.proportion": "0.2", "settings.editor.selected.configurable": "MavenSettings", @@ -89,7 +101,7 @@
- + + + + + + + @@ -136,7 +258,12 @@ - + + + + + + 1677144154839 @@ -194,7 +321,14 @@ - diff --git a/pom.xml b/pom.xml index 8f018d6..f5eacb5 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ org.example blog - 1.0-SNAPSHOT + haha war diff --git a/src/main/java/cn/zyq/vesionone/filter/CheckFilter.java b/src/main/java/cn/zyq/vesionone/filter/CheckFilter.java index 2e81587..1e200cd 100644 --- a/src/main/java/cn/zyq/vesionone/filter/CheckFilter.java +++ b/src/main/java/cn/zyq/vesionone/filter/CheckFilter.java @@ -12,9 +12,13 @@ import java.io.IOException; public class CheckFilter extends HttpServlet implements Filter{ public void init(FilterConfig config) throws ServletException { + + int a = 3; + } public void destroy() { + int a = 3; } @Override diff --git a/src/main/java/cn/zyq/vesionone/filter/SolveChineseTransFilter.java b/src/main/java/cn/zyq/vesionone/filter/SolveChineseTransFilter.java index e263789..1ca58cb 100644 --- a/src/main/java/cn/zyq/vesionone/filter/SolveChineseTransFilter.java +++ b/src/main/java/cn/zyq/vesionone/filter/SolveChineseTransFilter.java @@ -7,9 +7,11 @@ import java.io.IOException; @WebFilter("/*") public class SolveChineseTransFilter implements Filter { public void init(FilterConfig config) throws ServletException { + int a = 3; } public void destroy() { + int a = 3; } @Override diff --git a/src/main/java/cn/zyq/vesionone/web/EditBlogServlet.java b/src/main/java/cn/zyq/vesionone/web/EditBlogServlet.java index a956744..0165cc8 100644 --- a/src/main/java/cn/zyq/vesionone/web/EditBlogServlet.java +++ b/src/main/java/cn/zyq/vesionone/web/EditBlogServlet.java @@ -30,7 +30,7 @@ public class EditBlogServlet extends HttpServlet { // 获取编辑页面提交的数据 String title = request.getParameter("title"); String category = request.getParameter("category"); - String editContext = request.getParameter("editContext"); + String editContext = request.getParameter("my-editormd-html-code"); // 测试用 // System.out.println(title); // System.out.println(category); diff --git a/src/main/webapp/edit.html b/src/main/webapp/edit.html index 2166eb1..56632ff 100644 --- a/src/main/webapp/edit.html +++ b/src/main/webapp/edit.html @@ -26,12 +26,12 @@
博客标题: 博客分类: -
- 博客内容:
-
- +
+ + +
@@ -43,15 +43,17 @@ -- Gitee