From 6a0842d09b29ed97f921f207f678d84708284bdc Mon Sep 17 00:00:00 2001
From: User_cyk <1020691186@qq.com>
Date: Fri, 30 Jun 2023 16:48:55 +0800
Subject: [PATCH] =?UTF-8?q?=E6=9C=88=E5=88=8A=E9=A1=B5=E9=9D=A2=E6=8E=A5?=
=?UTF-8?q?=E5=8F=A3?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
helloGithub.iml | 4 +-
src/com/hellogithub/dao/UserDao.java | 12 +-
src/com/hellogithub/dao/projectDao.java | 69 +++++++++++
src/com/hellogithub/entity/AdminEntity.java | 4 -
src/com/hellogithub/entity/adminEntity.java | 8 ++
src/com/hellogithub/entity/articleEntity.java | 54 +++++++++
.../hellogithub/entity/categoryEntity.java | 32 +++++
src/com/hellogithub/entity/commentEntity.java | 69 +++++++++++
.../entity/projectCategoryEntity.java | 31 +++++
src/com/hellogithub/entity/projectEntity.java | 114 ++++++++++++++++++
.../{UserEntity.java => userEntity.java} | 8 +-
src/com/hellogithub/service/UserService.java | 6 +-
.../hellogithub/service/projectService.java | 16 +++
.../hellogithub/servlet/UserLoginServlet.java | 5 +-
.../servlet/UserRegisterServlet.java | 4 +-
.../hellogithub/servlet/countNumServlet.java | 47 ++++++++
.../hellogithub/servlet/latestServlet.java | 45 +++++++
.../servlet/selectCateServlet.java | 45 +++++++
.../servlet/selectTermServlet.java | 46 +++++++
19 files changed, 595 insertions(+), 24 deletions(-)
create mode 100644 src/com/hellogithub/dao/projectDao.java
delete mode 100644 src/com/hellogithub/entity/AdminEntity.java
create mode 100644 src/com/hellogithub/entity/adminEntity.java
create mode 100644 src/com/hellogithub/entity/articleEntity.java
create mode 100644 src/com/hellogithub/entity/categoryEntity.java
create mode 100644 src/com/hellogithub/entity/commentEntity.java
create mode 100644 src/com/hellogithub/entity/projectCategoryEntity.java
create mode 100644 src/com/hellogithub/entity/projectEntity.java
rename src/com/hellogithub/entity/{UserEntity.java => userEntity.java} (94%)
create mode 100644 src/com/hellogithub/service/projectService.java
create mode 100644 src/com/hellogithub/servlet/countNumServlet.java
create mode 100644 src/com/hellogithub/servlet/latestServlet.java
create mode 100644 src/com/hellogithub/servlet/selectCateServlet.java
create mode 100644 src/com/hellogithub/servlet/selectTermServlet.java
diff --git a/helloGithub.iml b/helloGithub.iml
index 0203694..08d1f59 100644
--- a/helloGithub.iml
+++ b/helloGithub.iml
@@ -17,8 +17,8 @@
-
+
-
+
\ No newline at end of file
diff --git a/src/com/hellogithub/dao/UserDao.java b/src/com/hellogithub/dao/UserDao.java
index 455b7d7..6869e0b 100644
--- a/src/com/hellogithub/dao/UserDao.java
+++ b/src/com/hellogithub/dao/UserDao.java
@@ -1,6 +1,6 @@
package com.hellogithub.dao;
-import com.hellogithub.entity.UserEntity;
+import com.hellogithub.entity.userEntity;
import com.hellogithub.utils.JdbcUtils;
import java.sql.Connection;
@@ -12,7 +12,7 @@ import java.sql.ResultSet;
* 用户Dao层
*/
public class UserDao {
- private UserEntity userEntity = new UserEntity();
+ private com.hellogithub.entity.userEntity userEntity = new userEntity();
/**
* 用户登录
@@ -20,7 +20,7 @@ public class UserDao {
* @param userName
* @param password
*/
- public UserEntity UserLogin(String userName, String password) {
+ public com.hellogithub.entity.userEntity UserLogin(String userName, String password) {
ResultSet resultSet = null;
PreparedStatement preparedStatement = null;
Connection connection = null;
@@ -38,7 +38,7 @@ public class UserDao {
Integer id = resultSet.getInt(1);
String dbUserName = resultSet.getString(2);
String dbUserPassword = resultSet.getString(3);
- userEntity = new UserEntity(dbUserName, dbUserPassword);
+ userEntity = new userEntity(dbUserName, dbUserPassword);
return userEntity;
} catch (Exception e) {
e.printStackTrace();
@@ -87,7 +87,7 @@ public class UserDao {
*
* @param userName
*/
- public UserEntity findByUserName(String userName) {
+ public com.hellogithub.entity.userEntity findByUserName(String userName) {
ResultSet resultSet = null;
PreparedStatement preparedStatement = null;
Connection connection = null;
@@ -104,7 +104,7 @@ public class UserDao {
Integer id = resultSet.getInt(1);
String dbUserName = resultSet.getString(2);
String dbUserPwd = resultSet.getString(3);
- UserEntity mayiktUserEntity = new UserEntity(dbUserName, dbUserPwd);
+ com.hellogithub.entity.userEntity mayiktUserEntity = new userEntity(dbUserName, dbUserPwd);
return mayiktUserEntity;
} catch (Exception e) {
e.printStackTrace();
diff --git a/src/com/hellogithub/dao/projectDao.java b/src/com/hellogithub/dao/projectDao.java
new file mode 100644
index 0000000..1bf19fe
--- /dev/null
+++ b/src/com/hellogithub/dao/projectDao.java
@@ -0,0 +1,69 @@
+package com.hellogithub.dao;
+
+import com.hellogithub.entity.projectEntity;
+import com.hellogithub.utils.JdbcUtils;
+import org.apache.commons.dbutils.QueryRunner;
+import org.apache.commons.dbutils.handlers.BeanHandler;
+import org.apache.commons.dbutils.handlers.BeanListHandler;
+
+import java.sql.Connection;
+import java.sql.SQLException;
+import java.util.List;
+
+public class projectDao {
+
+
+
+ public List retTerm(String num) {
+ List projectEntityList;
+ try {
+ Connection conn = JdbcUtils.getConnection();
+ QueryRunner runner = new QueryRunner();
+ String sql = "select * from project where periodicals = ?";
+ projectEntityList = runner.query(conn, sql, new BeanListHandler<>(projectEntity.class), num);
+ } catch (SQLException e) {
+ throw new RuntimeException(e);
+ }
+ return projectEntityList;
+ }
+
+ public int latestNum() {
+ projectEntity projectEntity;
+ try {
+ Connection conn = JdbcUtils.getConnection();
+ QueryRunner runner = new QueryRunner();
+ String sql = "select * from project Group BY periodicals DESC limit 1";
+ projectEntity = runner.query(conn, sql, new BeanHandler<>(projectEntity.class));
+ } catch (SQLException e) {
+ throw new RuntimeException(e);
+ }
+ return projectEntity.getPeriodicals();
+ }
+
+ public int countAll() {
+ int count;
+ try {
+ Connection conn = JdbcUtils.getConnection();
+ QueryRunner runner = new QueryRunner();
+ String sql = "select count(1) from project";
+ count = runner.query(conn, sql, new BeanHandler<>(Integer.class));
+ } catch (SQLException e) {
+ throw new RuntimeException(e);
+ }
+ return count;
+ }
+
+
+ public List retCate(int num) {
+ List projectEntityList;
+ try {
+ Connection conn = JdbcUtils.getConnection();
+ QueryRunner runner = new QueryRunner();
+ String sql = "select * from project where categoryId = ?";
+ projectEntityList = runner.query(conn, sql, new BeanListHandler<>(projectEntity.class), num);
+ } catch (SQLException e) {
+ throw new RuntimeException(e);
+ }
+ return projectEntityList;
+ }
+}
diff --git a/src/com/hellogithub/entity/AdminEntity.java b/src/com/hellogithub/entity/AdminEntity.java
deleted file mode 100644
index 4684a9c..0000000
--- a/src/com/hellogithub/entity/AdminEntity.java
+++ /dev/null
@@ -1,4 +0,0 @@
-package com.hellogithub.entity;
-
-public class AdminEntity {
-}
diff --git a/src/com/hellogithub/entity/adminEntity.java b/src/com/hellogithub/entity/adminEntity.java
new file mode 100644
index 0000000..116f0e2
--- /dev/null
+++ b/src/com/hellogithub/entity/adminEntity.java
@@ -0,0 +1,8 @@
+package com.hellogithub.entity;
+
+public class adminEntity {
+ int adminId;
+ String adminName;
+ String adminPassword;
+ int isValid;
+}
diff --git a/src/com/hellogithub/entity/articleEntity.java b/src/com/hellogithub/entity/articleEntity.java
new file mode 100644
index 0000000..fcc7965
--- /dev/null
+++ b/src/com/hellogithub/entity/articleEntity.java
@@ -0,0 +1,54 @@
+package com.hellogithub.entity;
+
+public class articleEntity {
+
+ int articleId;
+
+ int userId;
+
+ public int getArticleId() {
+ return articleId;
+ }
+
+ public void setArticleId(int articleId) {
+ this.articleId = articleId;
+ }
+
+ public int getUserId() {
+ return userId;
+ }
+
+ public void setUserId(int userId) {
+ this.userId = userId;
+ }
+
+ public String getArticleContent() {
+ return articleContent;
+ }
+
+ public void setArticleContent(String articleContent) {
+ this.articleContent = articleContent;
+ }
+
+ public String getPublishTime() {
+ return publishTime;
+ }
+
+ public void setPublishTime(String publishTime) {
+ this.publishTime = publishTime;
+ }
+
+ public int getIsValid() {
+ return isValid;
+ }
+
+ public void setIsValid(int isValid) {
+ this.isValid = isValid;
+ }
+
+ String articleContent;
+
+ String publishTime;
+ int isValid;
+
+}
diff --git a/src/com/hellogithub/entity/categoryEntity.java b/src/com/hellogithub/entity/categoryEntity.java
new file mode 100644
index 0000000..c20d5dd
--- /dev/null
+++ b/src/com/hellogithub/entity/categoryEntity.java
@@ -0,0 +1,32 @@
+package com.hellogithub.entity;
+
+public class categoryEntity {
+ int categoryId;
+ String category;
+
+ public int getCategoryId() {
+ return categoryId;
+ }
+
+ public void setCategoryId(int categoryId) {
+ this.categoryId = categoryId;
+ }
+
+ public String getCategory() {
+ return category;
+ }
+
+ public void setCategory(String category) {
+ this.category = category;
+ }
+
+ public int getIsValid() {
+ return isValid;
+ }
+
+ public void setIsValid(int isValid) {
+ this.isValid = isValid;
+ }
+
+ int isValid;
+}
diff --git a/src/com/hellogithub/entity/commentEntity.java b/src/com/hellogithub/entity/commentEntity.java
new file mode 100644
index 0000000..d247946
--- /dev/null
+++ b/src/com/hellogithub/entity/commentEntity.java
@@ -0,0 +1,69 @@
+package com.hellogithub.entity;
+
+import java.util.Date;
+
+public class commentEntity {
+ int commentId;
+ int userId;
+ int projectId;
+ String content;
+ int isUsed;
+ Date commentTime;
+ int isValid;
+
+ public int getCommentId() {
+ return commentId;
+ }
+
+ public void setCommentId(int commentId) {
+ this.commentId = commentId;
+ }
+
+ public int getUserId() {
+ return userId;
+ }
+
+ public void setUserId(int userId) {
+ this.userId = userId;
+ }
+
+ public int getProjectId() {
+ return projectId;
+ }
+
+ public void setProjectId(int projectId) {
+ this.projectId = projectId;
+ }
+
+ public String getContent() {
+ return content;
+ }
+
+ public void setContent(String content) {
+ this.content = content;
+ }
+
+ public int getIsUsed() {
+ return isUsed;
+ }
+
+ public void setIsUsed(int isUsed) {
+ this.isUsed = isUsed;
+ }
+
+ public Date getCommentTime() {
+ return commentTime;
+ }
+
+ public void setCommentTime(Date commentTime) {
+ this.commentTime = commentTime;
+ }
+
+ public int getIsValid() {
+ return isValid;
+ }
+
+ public void setIsValid(int isValid) {
+ this.isValid = isValid;
+ }
+}
diff --git a/src/com/hellogithub/entity/projectCategoryEntity.java b/src/com/hellogithub/entity/projectCategoryEntity.java
new file mode 100644
index 0000000..45f5624
--- /dev/null
+++ b/src/com/hellogithub/entity/projectCategoryEntity.java
@@ -0,0 +1,31 @@
+package com.hellogithub.entity;
+
+public class projectCategoryEntity {
+ int id;
+ int categoryId;
+ int projectId;
+
+ public int getId() {
+ return id;
+ }
+
+ public void setId(int id) {
+ this.id = id;
+ }
+
+ public int getCategoryId() {
+ return categoryId;
+ }
+
+ public void setCategoryId(int categoryId) {
+ this.categoryId = categoryId;
+ }
+
+ public int getProjectId() {
+ return projectId;
+ }
+
+ public void setProjectId(int projectId) {
+ this.projectId = projectId;
+ }
+}
diff --git a/src/com/hellogithub/entity/projectEntity.java b/src/com/hellogithub/entity/projectEntity.java
new file mode 100644
index 0000000..3ea3c23
--- /dev/null
+++ b/src/com/hellogithub/entity/projectEntity.java
@@ -0,0 +1,114 @@
+package com.hellogithub.entity;
+
+import java.util.Date;
+
+public class projectEntity {
+ int projectId;
+ int userId;
+ String projectUrl;
+ String projectIco;
+ String projectTitle;
+ String projectDescription;
+ int startNum;
+ Date submitTime;
+ int categoryId;
+ int isValid;
+ String fileAddress;
+ int periodicals;
+
+ public int getProjectId() {
+ return projectId;
+ }
+
+ public void setProjectId(int projectId) {
+ this.projectId = projectId;
+ }
+
+ public int getUserId() {
+ return userId;
+ }
+
+ public void setUserId(int userId) {
+ this.userId = userId;
+ }
+
+ public String getProjectUrl() {
+ return projectUrl;
+ }
+
+ public void setProjectUrl(String projectUrl) {
+ this.projectUrl = projectUrl;
+ }
+
+ public String getProjectIco() {
+ return projectIco;
+ }
+
+ public void setProjectIco(String projectIco) {
+ this.projectIco = projectIco;
+ }
+
+ public String getProjectTitle() {
+ return projectTitle;
+ }
+
+ public void setProjectTitle(String projectTitle) {
+ this.projectTitle = projectTitle;
+ }
+
+ public String getProjectDescription() {
+ return projectDescription;
+ }
+
+ public void setProjectDescription(String projectDescription) {
+ this.projectDescription = projectDescription;
+ }
+
+ public int getStartNum() {
+ return startNum;
+ }
+
+ public void setStartNum(int startNum) {
+ this.startNum = startNum;
+ }
+
+ public Date getSubmitTime() {
+ return submitTime;
+ }
+
+ public void setSubmitTime(Date submitTime) {
+ this.submitTime = submitTime;
+ }
+
+ public int getCategoryId() {
+ return categoryId;
+ }
+
+ public void setCategoryId(int categoryId) {
+ this.categoryId = categoryId;
+ }
+
+ public int getIsValid() {
+ return isValid;
+ }
+
+ public void setIsValid(int isValid) {
+ this.isValid = isValid;
+ }
+
+ public String getFileAddress() {
+ return fileAddress;
+ }
+
+ public void setFileAddress(String fileAddress) {
+ this.fileAddress = fileAddress;
+ }
+
+ public int getPeriodicals() {
+ return periodicals;
+ }
+
+ public void setPeriodicals(int periodicals) {
+ this.periodicals = periodicals;
+ }
+}
diff --git a/src/com/hellogithub/entity/UserEntity.java b/src/com/hellogithub/entity/userEntity.java
similarity index 94%
rename from src/com/hellogithub/entity/UserEntity.java
rename to src/com/hellogithub/entity/userEntity.java
index 087b55c..a9939b5 100644
--- a/src/com/hellogithub/entity/UserEntity.java
+++ b/src/com/hellogithub/entity/userEntity.java
@@ -5,7 +5,7 @@ import java.sql.Date;
/**
* 用户实体层
*/
-public class UserEntity {
+public class userEntity {
/**
* CREATE TABLE `user` (
* `userId` int(11) NOT NULL AUTO_INCREMENT COMMENT '用户ID',
@@ -30,16 +30,16 @@ public class UserEntity {
private String searchHistory;
- public UserEntity() {
+ public userEntity() {
}
- public UserEntity(String userName, String userPassword) {
+ public userEntity(String userName, String userPassword) {
this.userName = userName;
this.userPassword = userPassword;
}
- public UserEntity(Integer userId, String userName, String userPassword, Date creatTime, Integer isValid, Integer projectNum, String searchHistory) {
+ public userEntity(Integer userId, String userName, String userPassword, Date creatTime, Integer isValid, Integer projectNum, String searchHistory) {
this.userId = userId;
this.userName = userName;
this.userPassword = userPassword;
diff --git a/src/com/hellogithub/service/UserService.java b/src/com/hellogithub/service/UserService.java
index 883b3c8..8bef108 100644
--- a/src/com/hellogithub/service/UserService.java
+++ b/src/com/hellogithub/service/UserService.java
@@ -1,7 +1,7 @@
package com.hellogithub.service;
import com.hellogithub.dao.UserDao;
-import com.hellogithub.entity.UserEntity;
+import com.hellogithub.entity.userEntity;
/**
* 用户Service层
@@ -13,7 +13,7 @@ public class UserService {
* @param userName
* @param password
* */
- public UserEntity UserLogin(String userName,String password){
+ public userEntity UserLogin(String userName, String password){
return userDao.UserLogin(userName,password);
}
/**
@@ -28,7 +28,7 @@ public class UserService {
* 通过用户名查询
* @param userName
* */
- public UserEntity findByUserName(String userName) {
+ public userEntity findByUserName(String userName) {
return userDao.findByUserName(userName);
}
}
diff --git a/src/com/hellogithub/service/projectService.java b/src/com/hellogithub/service/projectService.java
new file mode 100644
index 0000000..da51320
--- /dev/null
+++ b/src/com/hellogithub/service/projectService.java
@@ -0,0 +1,16 @@
+package com.hellogithub.service;
+
+import com.hellogithub.dao.UserDao;
+import com.hellogithub.dao.projectDao;
+import com.hellogithub.entity.projectEntity;
+
+import java.util.List;
+
+public class projectService {
+ private projectDao projectDao=new projectDao();
+
+ public List retTerm(String num){return projectDao.retTerm(num);}
+ public int latestNum() {return projectDao.latestNum();}
+ public int countAll() {return projectDao.countAll();}
+ public List retCate(int num){return projectDao.retCate(num);}
+}
diff --git a/src/com/hellogithub/servlet/UserLoginServlet.java b/src/com/hellogithub/servlet/UserLoginServlet.java
index 15d8a1c..fb9ee02 100644
--- a/src/com/hellogithub/servlet/UserLoginServlet.java
+++ b/src/com/hellogithub/servlet/UserLoginServlet.java
@@ -1,8 +1,7 @@
package com.hellogithub.servlet;
-import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
-import com.hellogithub.entity.UserEntity;
+import com.hellogithub.entity.userEntity;
import com.hellogithub.service.UserService;
import com.hellogithub.utils.RandomValidateCode;
import jakarta.servlet.ServletException;
@@ -59,7 +58,7 @@ public class UserLoginServlet extends HttpServlet {
return;
}
// 在调用业务逻辑层
- UserEntity adminUserEntity = userService.UserLogin(userName, userPwd);
+ userEntity adminUserEntity = userService.UserLogin(userName, userPwd);
if (adminUserEntity == null) {
// 用户名称或者密码错误!
setResultError("用户名或者密码错误!!!", writer);
diff --git a/src/com/hellogithub/servlet/UserRegisterServlet.java b/src/com/hellogithub/servlet/UserRegisterServlet.java
index 1258bbd..3ee2665 100644
--- a/src/com/hellogithub/servlet/UserRegisterServlet.java
+++ b/src/com/hellogithub/servlet/UserRegisterServlet.java
@@ -1,7 +1,7 @@
package com.hellogithub.servlet;
import com.alibaba.fastjson.JSONObject;
-import com.hellogithub.entity.UserEntity;
+import com.hellogithub.entity.userEntity;
import com.hellogithub.service.UserService;
import com.hellogithub.utils.RandomValidateCode;
import jakarta.servlet.ServletException;
@@ -60,7 +60,7 @@ public class UserRegisterServlet extends HttpServlet {
return;
}
// 用户注册之前根据用户名称查询该用户是否存在如果不存在的情况下才可以注册 如果存在的话就无法注册
- UserEntity userEntity = userService.findByUserName(userName);
+ userEntity userEntity = userService.findByUserName(userName);
if (userEntity != null) {
setResultError("用户名: " + userName + "已被注册!", writer);
return;
diff --git a/src/com/hellogithub/servlet/countNumServlet.java b/src/com/hellogithub/servlet/countNumServlet.java
new file mode 100644
index 0000000..fde58ae
--- /dev/null
+++ b/src/com/hellogithub/servlet/countNumServlet.java
@@ -0,0 +1,47 @@
+package com.hellogithub.servlet;
+
+import com.alibaba.fastjson.JSONObject;
+import com.hellogithub.dao.projectDao;
+import com.hellogithub.service.projectService;
+import jakarta.servlet.ServletConfig;
+import jakarta.servlet.ServletException;
+import jakarta.servlet.annotation.WebServlet;
+import jakarta.servlet.http.HttpServlet;
+import jakarta.servlet.http.HttpServletRequest;
+import jakarta.servlet.http.HttpServletResponse;
+
+import java.io.IOException;
+import java.io.PrintWriter;
+@WebServlet("/countNum")
+public class countNumServlet extends HttpServlet {
+ private projectService projectService=new projectService();
+ @Override
+ public void init(ServletConfig config) throws ServletException {
+
+ }
+
+ @Override
+ protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
+ doPost(req,resp);
+ }
+
+ @Override
+ protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
+ resp.setCharacterEncoding("UTF-8");
+ resp.setContentType("text/html; charset=utf-8");
+ // 设置响应头允许ajax跨域访问
+ String curOrigin = req.getHeader("Origin");
+ resp.setHeader("Access-Control-Allow-Origin", curOrigin == null ? "true" : curOrigin);
+ resp.setHeader("Access-Control-Allow-Credentials", "true");
+ resp.setHeader("Access-Control-Allow-Methods", "POST, GET, OPTIONS, DELETE, HEAD");
+ resp.setHeader("Access-Control-Max-Age", "3600");
+ resp.setHeader("Access-Control-Allow-Headers", "access-control-allow-origin, authority, content-type, version-info, X-Requested-With");
+ resp.setContentType("application/json;charset=UTF-8");
+
+ PrintWriter writer = resp.getWriter();
+ String str= "num:"+projectService.countAll();
+ String jsonString = JSONObject.toJSONString(str);
+ writer.println(jsonString);
+ writer.close();
+ }
+}
diff --git a/src/com/hellogithub/servlet/latestServlet.java b/src/com/hellogithub/servlet/latestServlet.java
new file mode 100644
index 0000000..981950a
--- /dev/null
+++ b/src/com/hellogithub/servlet/latestServlet.java
@@ -0,0 +1,45 @@
+package com.hellogithub.servlet;
+
+import com.alibaba.fastjson.JSONObject;
+import com.hellogithub.service.projectService;
+import jakarta.servlet.ServletConfig;
+import jakarta.servlet.ServletException;
+import jakarta.servlet.annotation.WebServlet;
+import jakarta.servlet.http.HttpServlet;
+import jakarta.servlet.http.HttpServletRequest;
+import jakarta.servlet.http.HttpServletResponse;
+
+import java.io.IOException;
+import java.io.PrintWriter;
+@WebServlet("/latest")
+public class latestServlet extends HttpServlet {
+ private com.hellogithub.service.projectService projectService=new projectService();
+ @Override
+ public void init(ServletConfig config) throws ServletException {
+
+ }
+
+ @Override
+ protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
+ doPost(req, resp);
+ }
+
+ @Override
+ protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
+ resp.setCharacterEncoding("UTF-8");
+ resp.setContentType("text/html; charset=utf-8");
+ // 设置响应头允许ajax跨域访问
+ String curOrigin = req.getHeader("Origin");
+ resp.setHeader("Access-Control-Allow-Origin", curOrigin == null ? "true" : curOrigin);
+ resp.setHeader("Access-Control-Allow-Credentials", "true");
+ resp.setHeader("Access-Control-Allow-Methods", "POST, GET, OPTIONS, DELETE, HEAD");
+ resp.setHeader("Access-Control-Max-Age", "3600");
+ resp.setHeader("Access-Control-Allow-Headers", "access-control-allow-origin, authority, content-type, version-info, X-Requested-With");
+ resp.setContentType("application/json;charset=UTF-8");
+
+ PrintWriter writer = resp.getWriter();
+ String jsonString = JSONObject.toJSONString(projectService.latestNum());
+ writer.println(jsonString);
+ writer.close();
+ }
+}
diff --git a/src/com/hellogithub/servlet/selectCateServlet.java b/src/com/hellogithub/servlet/selectCateServlet.java
new file mode 100644
index 0000000..fad00c8
--- /dev/null
+++ b/src/com/hellogithub/servlet/selectCateServlet.java
@@ -0,0 +1,45 @@
+package com.hellogithub.servlet;
+
+import com.alibaba.fastjson.JSONObject;
+import com.hellogithub.service.projectService;
+import jakarta.servlet.ServletConfig;
+import jakarta.servlet.ServletException;
+import jakarta.servlet.annotation.WebServlet;
+import jakarta.servlet.http.HttpServlet;
+import jakarta.servlet.http.HttpServletRequest;
+import jakarta.servlet.http.HttpServletResponse;
+import java.io.IOException;
+import java.io.PrintWriter;
+@WebServlet("/selectCate")
+public class selectCateServlet extends HttpServlet {
+ private projectService projectService=new projectService();
+ @Override
+ public void init(ServletConfig config) throws ServletException {
+
+ }
+
+ @Override
+ protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
+ doPost(req, resp);
+ }
+
+ @Override
+ protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
+ resp.setCharacterEncoding("UTF-8");
+ resp.setContentType("text/html; charset=utf-8");
+ // 设置响应头允许ajax跨域访问
+ String curOrigin = req.getHeader("Origin");
+ resp.setHeader("Access-Control-Allow-Origin", curOrigin == null ? "true" : curOrigin);
+ resp.setHeader("Access-Control-Allow-Credentials", "true");
+ resp.setHeader("Access-Control-Allow-Methods", "POST, GET, OPTIONS, DELETE, HEAD");
+ resp.setHeader("Access-Control-Max-Age", "3600");
+ resp.setHeader("Access-Control-Allow-Headers", "access-control-allow-origin, authority, content-type, version-info, X-Requested-With");
+ resp.setContentType("application/json;charset=UTF-8");
+
+ String num = req.getParameter("xxxxxxx");
+ PrintWriter writer = resp.getWriter();
+ String jsonString = JSONObject.toJSONString(projectService.retTerm(String.valueOf(num)));
+ writer.println(jsonString);
+ writer.close();
+ }
+}
diff --git a/src/com/hellogithub/servlet/selectTermServlet.java b/src/com/hellogithub/servlet/selectTermServlet.java
new file mode 100644
index 0000000..1fa2add
--- /dev/null
+++ b/src/com/hellogithub/servlet/selectTermServlet.java
@@ -0,0 +1,46 @@
+package com.hellogithub.servlet;
+
+import com.alibaba.fastjson.JSONObject;
+import com.hellogithub.service.projectService;
+import jakarta.servlet.ServletConfig;
+import jakarta.servlet.ServletException;
+import jakarta.servlet.annotation.WebServlet;
+import jakarta.servlet.http.HttpServlet;
+import jakarta.servlet.http.HttpServletRequest;
+import jakarta.servlet.http.HttpServletResponse;
+
+import java.io.IOException;
+import java.io.PrintWriter;
+@WebServlet("/selectTerm")
+public class selectTermServlet extends HttpServlet {
+ private projectService projectService=new projectService();
+ @Override
+ public void init(ServletConfig config) throws ServletException {
+
+ }
+
+ @Override
+ protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
+ doPost(req,resp);
+ }
+
+ @Override
+ protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
+ resp.setCharacterEncoding("UTF-8");
+ resp.setContentType("text/html; charset=utf-8");
+ // 设置响应头允许ajax跨域访问
+ String curOrigin = req.getHeader("Origin");
+ resp.setHeader("Access-Control-Allow-Origin", curOrigin == null ? "true" : curOrigin);
+ resp.setHeader("Access-Control-Allow-Credentials", "true");
+ resp.setHeader("Access-Control-Allow-Methods", "POST, GET, OPTIONS, DELETE, HEAD");
+ resp.setHeader("Access-Control-Max-Age", "3600");
+ resp.setHeader("Access-Control-Allow-Headers", "access-control-allow-origin, authority, content-type, version-info, X-Requested-With");
+ resp.setContentType("application/json;charset=UTF-8");
+
+ String num = req.getParameter("xxxxxxx");
+ PrintWriter writer = resp.getWriter();
+ String jsonString = JSONObject.toJSONString(projectService.retTerm(num));
+ writer.println(jsonString);
+ writer.close();
+ }
+}