潘祉岳202422280902个人部分

master
Yuex1ng 2024-12-30 15:20:16 +08:00
commit baae7eafd2
57 changed files with 2263 additions and 0 deletions

2
.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
/.idea/
/tomcat.8080/

68
pom.xml Normal file
View File

@ -0,0 +1,68 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.example</groupId>
<artifactId>tomcat_main</artifactId>
<version>1.0-SNAPSHOT</version>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>9</source>
<target>9</target>
</configuration>
</plugin>
</plugins>
</build>
<packaging>war</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
<java.version>11</java.version>
<tomcat.version>9.0.39</tomcat.version>
</properties>
<dependencies>
<!-- jstl表达式依赖-->
<dependency>
<groupId>javax.servlet.jsp.jstl</groupId>
<artifactId>javax.servlet.jsp.jstl-api</artifactId>
<version>1.2.1</version>
</dependency>
<!-- taglibs 标签库依赖-->
<dependency>
<groupId>taglibs</groupId>
<artifactId>standard</artifactId>
<version>1.1.2</version>
</dependency>
<!-- tomcat依赖-->
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-core</artifactId>
<version>9.0.39</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
<version>9.0.39</version>
<scope>provided</scope>
</dependency>
<!-- mysql依赖-->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.22</version>
</dependency>
</dependencies>
</project>

View File

@ -0,0 +1,25 @@
package com;
import java.io.File;
import org.apache.catalina.Context;
import org.apache.catalina.WebResourceRoot;
import org.apache.catalina.startup.Tomcat;
import org.apache.catalina.webresources.DirResourceSet;
import org.apache.catalina.webresources.StandardRoot;
public class Main {
public static void main(String[] args) throws Exception {
// 启动Tomcat:
Tomcat tomcat = new Tomcat();
tomcat.setPort(Integer.getInteger("port", 8080));
tomcat.getConnector();
// 创建webapp:
Context ctx = tomcat.addWebapp("", new File("src/main/webapp").getAbsolutePath());
WebResourceRoot resources = new StandardRoot(ctx);
resources.addPreResources(
new DirResourceSet(resources, "/WEB-INF/classes", new File("target/classes").getAbsolutePath(), "/"));
ctx.setResources(resources);
tomcat. start();
tomcat.getServer().await();
}
}

View File

@ -0,0 +1,72 @@
package com.bean;
import java.sql.Date;
public class Comment {
private int id;
private int post_id;
private String author;
private String content;
private java.sql.Date date;
public Comment() {}
public Comment(int id, int post_id, String author, String content, Date date) {
this.id = id;
this.post_id = post_id;
this.author = author;
this.content = content;
this.date = date;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public int getPost_id() {
return post_id;
}
public void setPost_id(int post_id) {
this.post_id = post_id;
}
public String getAuthor() {
return author;
}
public void setAuthor(String author) {
this.author = author;
}
public String getContent() {
return content;
}
public void setContent(String content) {
this.content = content;
}
public Date getDate() {
return date;
}
public void setDate(Date date) {
this.date = date;
}
@Override
public String toString() {
return "comment{" +
"id=" + id +
", post_id=" + post_id +
", author='" + author + '\'' +
", content='" + content + '\'' +
", date=" + date +
'}';
}
}

View File

@ -0,0 +1,93 @@
package com.bean;
public class Post {
private int id;
private String title;
private String author;
private String type;
private String content;
private java.sql.Date date;
public Post() {}
public Post(
int id, String title, String author, String type, String content, java.sql.Date date) {
this.id = id;
this.title = title;
this.author = author;
this.type = type;
this.content = content;
this.date = date;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getAuthor() {
return author;
}
public void setAuthor(String author) {
this.author = author;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public String getContent() {
return content;
}
public void setContent(String content) {
this.content = content;
}
public java.sql.Date getDate() {
return date;
}
public void setDate(java.sql.Date date) {
this.date = date;
}
@Override
public String toString() {
return "Post{"
+ "id="
+ id
+ ", title='"
+ title
+ '\''
+ ", author='"
+ author
+ '\''
+ ", type='"
+ type
+ '\''
+ ", content='"
+ content
+ '\''
+ ", date='"
+ date
+ '\''
+ '}';
}
}

View File

@ -0,0 +1,80 @@
package com.bean;
public class User {
private int uid;
private String name;
private String passwd;
private String sex;
private java.sql.Date rtime;
public User() {
this.sex = "man";
}
public User(int uid, String name, String passwd, String sex, java.sql.Date rtime) {
this.uid = uid;
this.name = name;
this.passwd = passwd;
this.sex = sex;
this.rtime = rtime;
}
public int getUid() {
return uid;
}
public void setUid(int uid) {
this.uid = uid;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getPasswd() {
return passwd;
}
public void setPasswd(String passwd) {
this.passwd = passwd;
}
public String getSex() {
return sex;
}
public void setSex(String sex) {
this.sex = sex;
}
public java.sql.Date getRtime() {
return rtime;
}
public void setRtime(java.sql.Date rtime) {
this.rtime = rtime;
}
@Override
public String toString() {
return "User{"
+ "uid="
+ uid
+ ", name='"
+ name
+ '\''
+ ", passwd='"
+ passwd
+ '\''
+ ", sex='"
+ sex
+ '\''
+ ", rtime="
+ rtime
+ '}';
}
}

View File

@ -0,0 +1,52 @@
package com.controller;
import com.bean.Comment;
import com.dao.iCommentDAO;
import com.service.CommentDAO;
import java.io.IOException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
@WebServlet("/CommentAdd")
public class CommentAdd extends HttpServlet {
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws IOException {
request.setCharacterEncoding("UTF-8");
int post_id = Integer.parseInt(request.getParameter("post_id").trim());
HttpSession session = request.getSession();
String author = (String) session.getAttribute("username_session");
String content = request.getParameter("content");
Comment comment = new Comment();
comment.setPost_id(post_id);
comment.setAuthor(author);
comment.setContent(content);
iCommentDAO iCommentDAO = new CommentDAO();
try {
iCommentDAO.create(comment);
response
.getWriter()
.print(
"<script type=\"text/javascript\">\n"
+ "window.location.href='post.jsp?id="+post_id +"'\n"
+ "</script>");
// response.sendRedirect("/mine.jsp");
} catch (Exception e) {
e.printStackTrace();
String info = "评论失败失败";
request.setAttribute("outputMessage",info);
response.sendRedirect("/info.jsp");
}
}
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws IOException {
doPost(request,response);
}
}

View File

@ -0,0 +1,55 @@
package com.controller;
import com.bean.Post;
import com.dao.IPostDAO;
import com.service.PostDAO;
import java.io.IOException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
@WebServlet("/PostWrite")
public class PostWrite extends HttpServlet {
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws IOException {
request.setCharacterEncoding("UTF-8");
String title = request.getParameter("title");
HttpSession session = request.getSession();
String author = (String) session.getAttribute("username_session");
String type = request.getParameter("ntype");
String content = request.getParameter("content");
Post post = new Post();
post.setTitle(title);
post.setAuthor(author);
post.setType(type);
post.setContent(content);
IPostDAO iPostDAO = new PostDAO();
try {
iPostDAO.create(post);
post = iPostDAO.findByTitle(post);
response
.getWriter()
.print(
"<script type=\"text/javascript\">\n"
+ "window.location.href='post.jsp?id="+post.getId()+"'\n"
+ "</script>");
} catch (Exception e) {
e.printStackTrace();
String info = "文章录入失败";
request.setAttribute("outputMessage",info);
response.sendRedirect("/info.jsp");
}
}
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws IOException {
doPost(request,response);
}
}

View File

@ -0,0 +1,56 @@
package com.controller;
import com.bean.User;
import com.dao.IUserDAO;
import com.service.UserDAO;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@WebServlet("/SignCheck")
public class SignCheck extends HttpServlet {
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws IOException {
String username = request.getParameter("username");
String userpwd = request.getParameter("userpwd");
String reuserpwd = request.getParameter("reuserpwd");
if (!userpwd.equals(reuserpwd)) {
String info = "两次输入的密码不一致";
request.setAttribute("outputMessage",info);
response.sendRedirect("/info.jsp");
}
IUserDAO iUserDAO = new UserDAO();
try {
if (!iUserDAO.check(username)){
String info = "用户名已存在";
request.setAttribute("outputMessage",info);
PrintWriter out = response.getWriter();
out.print("<h1>hello</1>");
response.sendRedirect("/info.jsp");
} else {
User user = new User();
user.setName(username);
user.setPasswd(userpwd);
iUserDAO.create(user);
response.sendRedirect("/index.html");
}
} catch (Exception e) {
e.printStackTrace();
}
}
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws IOException {
doPost(request,response);
}
}

View File

@ -0,0 +1,60 @@
package com.controller;
import com.bean.User;
import com.dao.IUserDAO;
import com.service.UserDAO;
import java.io.IOException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
@WebServlet("/loginCheck")
public class loginCheck extends HttpServlet {
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws IOException {
String userName = request.getParameter("username");
String userPwd = request.getParameter("userpwd");
String info;
User user = new User();
user.setName(userName);
user.setPasswd(userPwd);
IUserDAO iUserDAO = new UserDAO();
int i = 0;
try {
i = iUserDAO.check(user);
} catch (Exception e) {
e.printStackTrace();
}
HttpSession session = request.getSession();
response.setContentType("text/html;charset=utf-8");
switch (i) {
case -1:
info = "用户名不存在";
// out.print("<script>alert('username isn't
// exit');window.history.back(-1);</script>");
request.setAttribute("outputMessage", info);
response.sendRedirect("/info.jsp");
break;
case 0:
info = "密码不正确";
// out.print("<script>alert('password error');window.history.back(-1);</script>");
request.setAttribute("outputMessage", info);
response.sendRedirect("/info.jsp");
break;
case 1:
info = "登录成功";
session.setAttribute("username_session", userName);
request.setAttribute("outputMessage", info);
response.sendRedirect("/home.jsp");
break;
}
}
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws IOException {
doPost(request, response);
}
}

View File

@ -0,0 +1,15 @@
package com.dao;
import com.bean.Post;
import java.util.List;
public interface IPostDAO {
void create(Post post) throws Exception;
void remove(Post post) throws Exception ;
Post findById(Post post) throws Exception;
Post findByTitle(Post post) throws Exception;
List<Post> findByAuthor (String author) throws Exception;
List<Post> findByType (String type) throws Exception;
List<Post> findAll() throws Exception;
void update(Post post) throws Exception;
}

View File

@ -0,0 +1,15 @@
package com.dao;
import com.bean.User;
import java.util.List;
public interface IUserDAO {
void create(User user) throws Exception;
void remove(User user) throws Exception ;
User findById(User user) throws Exception;
User findByName(User user) throws Exception;
List<User> findAll() throws Exception;
void update(User user) throws Exception;
int check(User user) throws Exception;
boolean check(String name) throws Exception;
}

View File

@ -0,0 +1,17 @@
package com.dao;
import com.bean.Comment;
import com.bean.Post;
import com.bean.User;
import java.util.List;
public interface iCommentDAO {
void create(Comment comment) throws Exception;
void remove(Comment comment) throws Exception ;
Comment findById(Comment comment) throws Exception;
List<Comment> findByAuthor(User user) throws Exception;
List<Comment> findByPostId (Post post) throws Exception;
List<Comment> findAll() throws Exception;
void update(Comment comment) throws Exception;
}

View File

@ -0,0 +1,35 @@
package com.db;
import java.sql.*;
public class DBConn {
private static final String driverName = "com.mysql.cj.jdbc.Driver";
private static final String userName = "root";
private static final String userPwd = "1234";
private static final String dbName = "forumsys";
public static Connection getDBconnection() {
String url1 = "jdbc:mysql://localhost/" +dbName;
String url2 = "?user="+userName+"&password=" +userPwd;
String url3 = "&useUnicode=true&characterEncoding=UTF-8&&serverTimezone=UTC";
String url = url1+url2 +url3;
try{
Class.forName(driverName);
return DriverManager.getConnection(url);
}catch (Exception e) {
e.printStackTrace();
}
return null;
}
public static void closeDB(Connection conn, PreparedStatement pstm, ResultSet rs) {
try{
if (rs!=null) rs.close();
if (pstm!=null) pstm.close();
if (conn!=null) conn.close();
} catch (SQLException e){
e.printStackTrace();
}
}
}

View File

@ -0,0 +1,168 @@
package com.service;
import com.bean.Comment;
import com.bean.Post;
import com.bean.User;
import com.dao.iCommentDAO;
import com.db.DBConn;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
public class CommentDAO implements iCommentDAO {
protected static final String FIELDS_INSERT = "id,post_id,author,content,date";
protected static String INSERT_SQL =
"insert into comment (" + FIELDS_INSERT + ")" + "values(0,?,?,?,NOW())";
protected static String SELECT_SQL = "select " + FIELDS_INSERT + " from post where id=?";
protected static String SELECT_SQL2 = "select " + FIELDS_INSERT + " from post where post_id=?";
protected static String UPDATE_SQL =
"update post set" + " content=? where id=?";
protected static String DELETE_SQL = "delete from post where id=?";
@Override
public void create(Comment comment) throws Exception {
Connection conn;
PreparedStatement pstm;
conn = DBConn.getDBconnection();
assert conn != null;
pstm = conn.prepareStatement(INSERT_SQL);
pstm.setInt(1, comment.getPost_id());
pstm.setString(2, comment.getAuthor());
pstm.setString(3, comment.getContent());
pstm.executeUpdate();
DBConn.closeDB(conn, pstm, null);
}
@Override
public void remove(Comment comment) throws Exception {
Connection conn;
PreparedStatement pstm;
conn = DBConn.getDBconnection();
assert conn != null;
pstm = conn.prepareStatement(DELETE_SQL);
pstm.setInt(1, comment.getId());
pstm.executeUpdate();
DBConn.closeDB(conn, pstm, null);
}
@Override
public Comment findById(Comment comment) throws Exception {
Connection conn;
PreparedStatement pstm;
ResultSet rs;
Comment comment1 = null;
conn = DBConn.getDBconnection();
assert conn != null;
pstm = conn.prepareStatement(SELECT_SQL);
pstm.setInt(1, comment.getId());
rs = pstm.executeQuery();
if (rs.next()) {
comment1 =
new Comment(
rs.getInt(1),
rs.getInt(2),
rs.getString(3),
rs.getString(4),
rs.getDate(6));
}
DBConn.closeDB(conn, pstm, rs);
return comment1;
}
@Override
public List<Comment> findByAuthor(User user) throws Exception {
Connection conn;
PreparedStatement pstm;
ResultSet rs;
List<Comment> comments = new ArrayList<>();
conn = DBConn.getDBconnection();
assert conn != null;
pstm = conn.prepareStatement("select * from comment where author=?");
pstm.setString(1, user.getName());
rs = pstm.executeQuery();
while (rs.next()) {
Comment comment =
new Comment(
rs.getInt(1),
rs.getInt(2),
rs.getString(3),
rs.getString(4),
rs.getDate(5));
comments.add(comment);
}
DBConn.closeDB(conn, pstm, rs);
return comments;
}
@Override
public List<Comment> findByPostId(Post post) throws Exception {
Connection conn;
PreparedStatement pstm;
ResultSet rs;
List<Comment> comments = new ArrayList<>();
conn = DBConn.getDBconnection();
assert conn != null;
pstm = conn.prepareStatement("select * from comment where post_id=?");
pstm.setInt(1, post.getId());
rs = pstm.executeQuery();
while (rs.next()) {
Comment comment =
new Comment(
rs.getInt(1),
rs.getInt(2),
rs.getString(3),
rs.getString(4),
rs.getDate(5));
comments.add(comment);
}
DBConn.closeDB(conn, pstm, rs);
return comments;
}
@Override
public List<Comment> findAll() throws Exception {
Connection conn;
PreparedStatement pstm;
ResultSet rs;
List<Comment> comments = new ArrayList<>();
conn = DBConn.getDBconnection();
assert conn != null;
pstm = conn.prepareStatement("select * from comment");
rs = pstm.executeQuery();
while (rs.next()) {
Comment comment =
new Comment(
rs.getInt(1),
rs.getInt(2),
rs.getString(3),
rs.getString(4),
rs.getDate(5));
comments.add(comment);
}
DBConn.closeDB(conn, pstm, rs);
return comments;
}
@Override
public void update(Comment comment) throws Exception {
Connection conn;
PreparedStatement pstm;
conn = DBConn.getDBconnection();
assert conn != null;
pstm = conn.prepareStatement(UPDATE_SQL);
pstm.setString(1, comment.getContent());
int rowCount = pstm.executeUpdate();
if (rowCount == 0) {
throw new SQLException("Update Error:Post id:" + comment.getId());
}
DBConn.closeDB(conn, pstm, null);
}
}

View File

@ -0,0 +1,200 @@
package com.service;
import com.bean.Post;
import com.dao.IPostDAO;
import com.db.DBConn;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
public class PostDAO implements IPostDAO {
protected static final String FIELDS_INSERT = "id, title, author, type, content, date";
protected static String INSERT_SQL =
"insert into post (" + FIELDS_INSERT + ")" + "values(0,?,?,?,?,NOW())";
protected static String SELECT_SQL = "select " + FIELDS_INSERT + " from post where id=?";
protected static String SELECT_SQL2 = "select " + FIELDS_INSERT + " from post where title=?";
protected static String UPDATE_SQL =
"update post set" + " title=?,author=?,type=?,content=? where id=?";
protected static String DELETE_SQL = "delete from post where id=?";
@Override
public void create(Post post) throws Exception {
Connection conn;
PreparedStatement pstm;
conn = DBConn.getDBconnection();
assert conn != null;
pstm = conn.prepareStatement(INSERT_SQL);
pstm.setString(1, post.getTitle());
pstm.setString(2, post.getAuthor());
pstm.setString(3, post.getType());
pstm.setString(4, post.getContent());
pstm.executeUpdate();
DBConn.closeDB(conn, pstm, null);
}
@Override
public void remove(Post post) throws Exception {
Connection conn;
PreparedStatement pstm;
conn = DBConn.getDBconnection();
assert conn != null;
pstm = conn.prepareStatement(DELETE_SQL);
pstm.setInt(1, post.getId());
pstm.executeUpdate();
DBConn.closeDB(conn, pstm, null);
}
@Override
public Post findById(Post post) throws Exception {
Connection conn;
PreparedStatement pstm;
ResultSet rs;
Post post2 = null;
conn = DBConn.getDBconnection();
assert conn != null;
pstm = conn.prepareStatement(SELECT_SQL);
pstm.setInt(1, post.getId());
rs = pstm.executeQuery();
if (rs.next()) {
post2 =
new Post(
rs.getInt(1),
rs.getString(2),
rs.getString(3),
rs.getString(4),
rs.getString(5),
rs.getDate(6));
}
DBConn.closeDB(conn, pstm, rs);
return post2;
}
@Override
public Post findByTitle(Post post) throws Exception {
Connection conn;
PreparedStatement pstm;
ResultSet rs;
Post post2 = null;
conn = DBConn.getDBconnection();
assert conn != null;
pstm = conn.prepareStatement(SELECT_SQL2);
pstm.setString(1, post.getTitle());
rs = pstm.executeQuery();
if (rs.next()) {
post2 =
new Post(
rs.getInt(1),
rs.getString(2),
rs.getString(3),
rs.getString(4),
rs.getString(5),
rs.getDate(6));
}
DBConn.closeDB(conn, pstm, rs);
return post2;
}
@Override
public List<Post> findByAuthor(String author) throws Exception {
Connection conn;
PreparedStatement pstm;
ResultSet rs;
List<Post> posts = new ArrayList<>();
conn = DBConn.getDBconnection();
assert conn != null;
pstm = conn.prepareStatement("select * from post where author=?");
pstm.setString(1, author);
rs = pstm.executeQuery();
while (rs.next()) {
Post post2 =
new Post(
rs.getInt(1),
rs.getString(2),
rs.getString(3),
rs.getString(4),
rs.getString(5),
rs.getDate(6));
posts.add(post2);
}
DBConn.closeDB(conn, pstm, rs);
return posts;
}
@Override
public List<Post> findByType(String type) throws Exception {
Connection conn;
PreparedStatement pstm;
ResultSet rs;
List<Post> posts = new ArrayList<>();
conn = DBConn.getDBconnection();
assert conn != null;
pstm = conn.prepareStatement("select * from post where type=?");
pstm.setString(1, type);
rs = pstm.executeQuery();
while (rs.next()) {
Post post2 =
new Post(
rs.getInt(1),
rs.getString(2),
rs.getString(3),
rs.getString(4),
rs.getString(5),
rs.getDate(6));
posts.add(post2);
}
DBConn.closeDB(conn, pstm, rs);
return posts;
}
@Override
public List<Post> findAll() throws Exception {
Connection conn;
PreparedStatement pstm;
ResultSet rs;
List<Post> posts = new ArrayList<>();
conn = DBConn.getDBconnection();
assert conn != null;
pstm = conn.prepareStatement("select * from post");
rs = pstm.executeQuery();
while (rs.next()) {
Post post2 =
new Post(
rs.getInt(1),
rs.getString(2),
rs.getString(3),
rs.getString(4),
rs.getString(5),
rs.getDate(6));
posts.add(post2);
}
DBConn.closeDB(conn, pstm, rs);
return posts;
}
@Override
public void update(Post post) throws Exception {
Connection conn;
PreparedStatement pstm;
conn = DBConn.getDBconnection();
assert conn != null;
pstm = conn.prepareStatement(UPDATE_SQL);
pstm.setString(1, post.getTitle());
pstm.setString(2, post.getAuthor());
pstm.setString(3, post.getType());
pstm.setString(4, post.getContent());
pstm.setInt(5, post.getId());
int rowCount = pstm.executeUpdate();
if (rowCount == 0) {
throw new SQLException("Update Error:Post id:" + post.getId());
}
DBConn.closeDB(conn, pstm, null);
}
}

View File

@ -0,0 +1,164 @@
package com.service;
import com.bean.User;
import com.dao.IUserDAO;
import com.db.DBConn;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
public class UserDAO implements IUserDAO {
protected static final String FIELDS_INSERT = "uid, name, passwd, sex, rtime";
protected static String INSERT_SQL = "insert into user (" + FIELDS_INSERT+ ")" +"values(0,?,?,?,NOW())";
protected static String SELECT_SQL = "select " + FIELDS_INSERT + " from user where uid=?";
protected static String SELECT_SQL2 = "select " + FIELDS_INSERT + " from user where name=?";
protected static String UPDATE_SQL = "update user set" + " name=?,passwd=?,sex=? where uid=?";
protected static String DELETE_SQL = "delete from user where uid=?";
@Override
public void create(User user) throws Exception {
Connection conn;
PreparedStatement pstm;
conn = DBConn.getDBconnection();
assert conn != null;
pstm = conn.prepareStatement(INSERT_SQL);
pstm.setString(1, user.getName());
pstm.setString(2,user.getPasswd());
pstm.setString(3,user.getSex());
pstm.executeUpdate();
DBConn.closeDB(conn,pstm,null);
}
@Override
public void remove(User user) throws Exception {
Connection conn;
PreparedStatement pstm;
conn = DBConn.getDBconnection();
assert conn != null;
pstm = conn.prepareStatement(DELETE_SQL);
pstm.setInt(1,user.getUid());
pstm.executeUpdate();
DBConn.closeDB(conn,pstm,null);
}
@Override
public User findById(User user) throws Exception {
Connection conn;
PreparedStatement pstm;
ResultSet rs;
User user2 = null;
conn = DBConn.getDBconnection();
assert conn != null;
pstm = conn.prepareStatement(SELECT_SQL);
pstm.setInt(1,user.getUid());
rs = pstm.executeQuery();
if (rs.next()){
user2 = new User(rs.getInt(1),rs.getString(2),rs.getString(3),rs.getString(4),rs.getDate(5));
}
DBConn.closeDB(conn,pstm,rs);
return user2;
}
@Override
public User findByName(User user) throws Exception {
Connection conn;
PreparedStatement pstm;
ResultSet rs;
User user2 = null;
conn = DBConn.getDBconnection();
assert conn != null;
pstm = conn.prepareStatement(SELECT_SQL2);
pstm.setString(1,user.getName());
rs = pstm.executeQuery();
if (rs.next()){
user2 = new User(rs.getInt(1),rs.getString(2),rs.getString(3),rs.getString(4),rs.getDate(5));
}
DBConn.closeDB(conn,pstm,rs);
return user2;
}
@Override
public List<User> findAll() throws Exception {
Connection conn;
PreparedStatement pstm;
ResultSet rs;
List<User> user = new ArrayList<>();
conn = DBConn.getDBconnection();
assert conn != null;
pstm = conn.prepareStatement("select * from user");
rs = pstm.executeQuery();
while (rs.next()){
User user1 = new User(rs.getInt(1),rs.getString(2),rs.getString(3),rs.getString(4),rs.getDate(5));
user.add(user1);
}
DBConn.closeDB(conn,pstm,rs);
return user;
}
@Override
public void update(User user) throws Exception {
Connection conn;
PreparedStatement pstm;
conn = DBConn.getDBconnection();
assert conn != null;
pstm = conn.prepareStatement(UPDATE_SQL);
pstm.setString(1,user.getName());
pstm.setString(2,user.getPasswd());
pstm.setString(3,user.getSex());
pstm.setInt(4,user.getUid());
int rowCount = pstm.executeUpdate();
if (rowCount == 0) {
throw new SQLException("Update Error:User uid:" + user.getUid());
}
DBConn.closeDB(conn,pstm,null);
}
@Override
public int check(User user) throws Exception{
Connection conn;
PreparedStatement pstm;
ResultSet rs;
conn = DBConn.getDBconnection();
assert conn != null;
pstm = conn.prepareStatement("select name,passwd from User where name=?");
pstm.setString(1,user.getName());
rs = pstm.executeQuery();
User user1 = new User();
if (rs.next()){
user1.setName(rs.getString(1));
user1.setPasswd(rs.getString(2));
}
if (!user.getName().equals(user1.getName())) {
return -1; // 用户名不存在返回-1
} else {
if (!user.getPasswd().equals(user1.getPasswd())) {
return 0; // 密码不正确返回0
} else {
return 1; // 正确返回1
}
}
}
public boolean check(String name) throws Exception {
Connection conn;
PreparedStatement pstm;
ResultSet rs;
conn = DBConn.getDBconnection();
assert conn != null;
pstm = conn.prepareStatement("select name from User where name=?");
pstm.setString(1,name);
rs = pstm.executeQuery();
User user1 = new User();
if (rs.next()){
user1.setName(rs.getString(1));
}
return !name.equals(user1.getName()); // 用户名存在返回0
}
}

View File

@ -0,0 +1,6 @@
<!DOCTYPE web-app PUBLIC
"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
<display-name>Archetype Created Web Application</display-name>
</web-app>

View File

@ -0,0 +1,48 @@
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="stylesheet" href="css/universal.css" />
<link rel="stylesheet" href="css/about.css" />
<title>FORUM</title>
<link rel="icon" href="images/moon.png" type="image/x-icon" />
</head>
<body>
<div class="header">
<h1>FORUM</h1>
<p>Everyone loves something.</p>
</div>
<div class="topnav">
<ul>
<li><a href="home.jsp">首页</a></li>
<li><a href="mine.jsp">我的</a></li>
<li><a href="publish.html">发帖</a></li>
<li><a href="home_login.jsp">账号</a></li>
<li><a href="about.html">关于</a></li>
</ul>
</div>
<div class="row">
<div class="card">
<h3>关于</h3>
<br>
<h2>🎈可以在论坛内出个人二手物品,但是不允许带货哦!<br>
🎈广告、兼职信息需要先找管理员审核,未经审核的广告或兼职帖子直接删除!<br>
多次违规提醒不听的将会禁言提醒甚至封禁账号<br>
希望大家可以遵守,方便别人的同时,也方便自己哟~
</h2>
</div>
</div>
<div class="footer">
<h2>Everyone loves something.</h2>
</div>
</body>
</html>

View File

@ -0,0 +1,19 @@
.row .card {
min-height: 700px;
}
.row h2 {
text-align: center;
margin-top: 200px;
}
@keyframes cardContainerLoad {
from {
opacity: 0;
transform: translate3d(0, 1%, 0);
}
to {
opacity: 1;
transform: none;
}
}

View File

@ -0,0 +1,47 @@
.row input {
display: none;
}
/* Create two unequal columns that floats next to each other */
/* Left column */
.leftcolumn {
float: left;
width: 34%;
}
.leftcolumn .card {
min-height: 700px;
}
/* Right column */
.rightcolumn {
float: left;
width: 66%;
padding-left: 20px;
}
.rightcolumn .card {
min-height: 340px;
}
@keyframes cardContainerLoad {
from {
opacity: 0;
transform: translate3d(0, 10%, 0);
}
to {
opacity: 1;
transform: none;
}
}
/* Responsive layout - when the screen is less than
800px wide, make the two columns stack on top of
each other instead of next to each other */
@media screen and (max-width: 800px) {
.leftcolumn,
.rightcolumn {
width: 100%;
padding: 0;
}
}

View File

@ -0,0 +1,11 @@
.row {
text-align: center;
}
.row button {
margin: 20px;
width: 100px;
height: 50px;
font-size: 18px;
}

View File

@ -0,0 +1,35 @@
.row {
text-align: center;
}
.login {
text-align: center;
height: 180px;
width: 350px;
margin: auto;
margin-top: 150px;
margin-bottom: 20px;
top: 0;
left: 0;
right: 0;
bottom: 0;
border: 1px solid black;
border-radius: 0.5em;
}
.login input {
float: right;
margin-right: 20px;
width: 200px;
height: 25px;
}
.login button {
margin-top: 15px;
width: 180px;
height: 30px;
}
.row a {
color: #333;
}

View File

@ -0,0 +1,3 @@
.row input {
display: none;
}

11
src/main/webapp/css/nes.min.css vendored Normal file

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,105 @@
.row {
animation: cardContainerLoad 2s;
}
.row .card {
min-height: auto;
animation: none;
}
.row .comment {
margin-top: 0;
}
.row hr {
margin-left: 20px;
margin-right: 20px;
}
.comment .title {
position: relative;
float: left;
height: 45px;
width: 100%;
background-color: white;
}
.comment .title .text {
float: left;
height: 30px;
width: 80%;
margin-right: 0;
}
.comment .title .btn {
float: right;
margin: 5px;
margin-right: 20px;
}
.comment .title .btn button {
height: 30px;
width: 30px;
font-size: 20px;
}
.comment .title h3 {
padding-left: 20px;
background-color: white;
text-align: left;
color: #333;
}
.comment .cinput {
position: relative;
margin-left: 20px;
margin-right: 20px;
}
.comment .cinput input {
float: left;
height: 40px;
width: 80%;
}
.comment .cinput .btn {
float: right;
height: 40px;
width: 20%;
}
.comment .cinput .btn button {
margin-left: 20px;
height: 40px;
width: 50%;
}
.comment .comments {
margin: 20px;
}
.ifmt {
padding-top: 3px;
text-align: center;
}
.ifmt .author {
float: left;
width: 33%;
}
.ifmt .type {
float: left;
width: 33%;
}
.ifmt .date {
float: left;
width: 33%;
}
.content {
padding: 20px;
padding-top: 50px;
font-size: 18px;
}

View File

@ -0,0 +1,32 @@
.edit {
margin: 20px;
color: #333;
}
.edit input {
margin-left: 10px;
}
.edit input[type="text"] {
height: 2em;
width: 20em;
}
.edit textarea {
margin-left: 8%;
margin-right: 10%;
resize: none;
height: 20em;
width: 80%;
padding: 10px;
font-size: 17px;
}
.edit button {
margin-top: 30px;
margin-left: 8%;
margin-right: 10%;
width: 80%;
height: 40px;
font-size: 18px;
}

View File

@ -0,0 +1,3 @@
.login {
height: 200px;
}

View File

@ -0,0 +1,134 @@
* {
padding: 0;
margin: 0;
box-sizing: border-box;
}
body {
height: 100%;
font-family: Arial;
padding: 10px;
background-image: url(../images/image01.jpg);
background-size: cover;
padding-left: 20%;
padding-right: 20%;
/* background: #f1f1f1; */
}
/* Header/Blog Title */
.header {
padding: 18px;
text-align: center;
/* background-image: url(../images/image01.jpg); */
background-size: cover;
}
.header h1 {
font-size: 50px;
font-weight: bolder;
}
/* Style the top navigation bar */
.topnav {
overflow: hidden;
background-color: #333;
position: sticky;
top: 0;
box-shadow: 0 1px 1px 0 rgba(0, 0, 0, 0.2), 0 1px 1px 0 rgba(0, 0, 0, 0.19);
text-align: center;
}
.topnav ul {
list-style-type: none;
overflow: hidden;
}
.topnav li {
padding-left: 10px;
padding-right: 10px;
display: inline-block;
}
/* Style the topnav links */
.topnav a {
float: left;
display: block;
font-size: 20px;
font-weight: bolder;
color: #f2f2f2;
text-align: center;
padding: 14px 16px;
text-decoration: none;
}
/* Change color on hover */
.topnav a:hover {
background-color: #ddd;
color: black;
}
/* Responsive layout - when the screen is less than
400px wide, make the navigation links stack on top
of each other instead of next to each other */
@media screen and (max-width: 400px) {
.topnav a {
float: none;
width: 100%;
}
}
.row .posta {
padding-top: 3%;
padding-left: 3%;
}
.row .posta a {
text-decoration: none;
color: #333;
font-weight: bolder;
}
/* Clear floats after the columns */
.row:after {
content: "";
display: table;
clear: both;
}
/* Add a card effect for articles */
.card {
background-color: white;
/* padding: 20px; */
margin-top: 20px;
box-shadow: 0 4px 4px 0 rgba(0, 0, 0, 0.2), 0 4px 4px 0 rgba(0, 0, 0, 0.19);
animation: cardContainerLoad 2s;
}
.card h3 {
padding: 10px;
background-color: #333;
text-align: center;
color: white;
}
/* Footer */
.footer {
padding: 10px;
text-align: center;
color: #333;
margin-top: 20px;
}
button {
background-color: #333;
border: none;
cursor: pointer;
text-align: center;
color: white;
box-shadow: 0 2px 4px 0 rgba(0, 0, 0, 0.2), 0 2px 4px 0 rgba(0, 0, 0, 0.19);
}
button:hover {
background-color: #ddd;
color: black;
}

122
src/main/webapp/home.jsp Normal file
View File

@ -0,0 +1,122 @@
<%@ page import="com.dao.IPostDAO" %>
<%@ page import="com.bean.Post" %>
<%@ page import="java.util.List" %>
<%@ page import="com.service.PostDAO" %>
<%--
Created by IntelliJ IDEA.
User: yuex1ng
Date: 2023/12/21
Time: 11:24
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta http-equiv="Expires" content="0">
<meta http-equiv="kiben" content="no-cache">
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="stylesheet" href="css/universal.css" />
<link rel="stylesheet" href="css/home.css" />
<title>FORUM</title>
<link rel="icon" href="images/moon.png" type="image/x-icon" />
<link rel="shortcut icon" href="images/moon.png" type="image/x-icon" />
</head>
<body>
<div class="header">
<h1>FORUM</h1>
<p>Everyone loves something.</p>
</div>
<div class="topnav">
<ul>
<li><a href="home.jsp">首页</a></li>
<li><a href="mine.jsp">我的</a></li>
<li><a href="publish.html">发帖</a></li>
<li><a href="home_login.jsp">账号</a></li>
<li><a href="about.html">关于</a></li>
</ul>
</div>
<div class="row">
<div class="leftcolumn">
<div class="card">
<h3>表白墙</h3>
<br>
<%
IPostDAO iPostDAO = new PostDAO();
List<Post> posts = null;
try {
posts = iPostDAO.findByType("表白墙");
} catch (Exception e) {
e.printStackTrace();
}
assert posts != null;
for (Post post : posts) { %>
<form action="./post.jsp" method="post" id="form<%=post.getId()%>">
<label>
<input type="text" name="id" value="<%=post.getId()%>">
</label>
<div class="posta"><a href="" onclick="document.getElementById('form<%=post.getId()%>').submit();return false;"><%=post.getTitle()%></a></div>
</form>
<%
}
%>
</div>
</div>
<div class="rightcolumn">
<div class="card">
<h3>学习讨论</h3>
<br>
<%
try {
posts = iPostDAO.findByType("学习讨论");
} catch (Exception e) {
e.printStackTrace();
}
assert posts != null;
for (Post post : posts) { %>
<form action="./post.jsp" method="post" id="form<%=post.getId()%>">
<label>
<input type="text" name="id" value="<%=post.getId()%>">
</label>
<div class="posta"><a href="" onclick="document.getElementById('form<%=post.getId()%>').submit();return false;"><%=post.getTitle()%></a></div>
</form>
<%
}
%>
</div>
<div class="card">
<h3>校园生活</h3>
<br>
<%
try {
posts = iPostDAO.findByType("校园生活");
} catch (Exception e) {
e.printStackTrace();
}
assert posts != null;
for (Post post : posts) { %>
<form action="./post.jsp" method="post" id="form<%=post.getId()%>">
<label>
<input type="text" name="id" value="<%=post.getId()%>">
</label>
<div class="posta"><a href="" onclick="document.getElementById('form<%=post.getId()%>').submit();return false;"><%=post.getTitle()%></a></div>
</form>
<%
}
%>
</div>
</div>
</div>
<div class="footer">
<h2>Everyone loves something.</h2>
</div>
</body>

View File

@ -0,0 +1,55 @@
<%--
Created by IntelliJ IDEA.
User: yuex1ng
Date: 2023/12/21
Time: 11:34
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="stylesheet" href="css/universal.css" />
<link rel="stylesheet" href="css/about.css" />
<link rel="stylesheet" href="css/home_login.css" />
<title>FORUM</title>
<link rel="icon" href="images/moon.png" type="image/x-icon" />
</head>
<body>
<div class="header">
<h1>FORUM</h1>
<p>Everyone loves something.</p>
</div>
<div class="topnav">
<ul>
<li><a href="home.jsp">首页</a></li>
<li><a href="mine.jsp">我的</a></li>
<li><a href="publish.html">发帖</a></li>
<li><a href="home_login.jsp">账号</a></li>
<li><a href="about.html">关于</a></li>
</ul>
</div>
<div class="row">
<div class="card">
<h3>当前登录</h3>
<br>
<h2><%=session.getAttribute("username_session")%>, 欢迎您</h2>
<button onclick="window.location.href='./index.html'">登出</button>
</div>
</div>
<div class="footer">
<h2>Everyone loves something.</h2>
</div>
</body>
</html>

Binary file not shown.

After

Width:  |  Height:  |  Size: 336 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 33 KiB

View File

@ -0,0 +1,56 @@
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="stylesheet" href="css/universal.css" />
<link rel="stylesheet" href="css/about.css" />
<link rel="stylesheet" href="css/index.css" />
<title>FORUM</title>
<link rel="icon" href="images/moon.png" type="image/x-icon" />
</head>
<body>
<div class="header">
<h1>FORUM</h1>
<p>Everyone loves something.</p>
</div>
<div class="topnav">
<ul>
<li><a href="#">首页</a></li>
<li><a href="#">我的</a></li>
<li><a href="#">发帖</a></li>
<li><a href="#">账号</a></li>
<li><a href="#">关于</a></li>
</ul>
</div>
<div class="row">
<div class="card">
<h3>登录</h3>
<br>
<div class="login">
<form action="loginCheck" method="post">
<br>
<label>用户名:<input type="text" name="username"></label>
<br><br>
<label>密 码:<input type="password" name="userpwd"></label>
<br><br>
<button type="submit">登录</button>
</form>
</div>
<br>
<a href="./signup.html">新用户注册</a>
</div>
</div>
<div class="footer">
<h2>Everyone loves something.</h2>
</div>
</body>
</html>

18
src/main/webapp/info.jsp Normal file
View File

@ -0,0 +1,18 @@
<%--
Created by IntelliJ IDEA.
User: yuex1ng
Date: 2023/12/21
Time: 12:51
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>Info</title>
</head>
<body>
<h1><%=request.getAttribute("outputMessage")%></h1>
<h1><%=session.getAttribute("session")%></h1>
<h1></h1>
</body>
</html>

View File

@ -0,0 +1,45 @@
//声明XMLHttpRequest对象
var httpRequest = null;
//创建XMLHttpRequest对象实例的方法
function createXHR() {
if (window.XMLHttpRequest) {
httpRequest = new XMLHttpRequest();
} else if (window.ActiveXObject) {
try {
httpRequest = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e) {
httpRequest = null;
}
}
}
if (!httpRequest) {
alert("fail to create httpRequest");
}
}
//发送客户端的请求该方法有4个参数
//参数url设置要连接的URL建立到服务器的连接并执行
//参数params为从Web表单中获取需要发送的数据集合
//参数method取值为POST或GET
//参数handler为指定的响应函数服务器在完成后要运行的回调函数
function sendRequest (url, params, method, handler) {
createXHR();
if (!httpRequest) {
return false;
}
httpRequest.onreadystatechange = handler;
if (method == "GET") {
httpRequest.open(method, url + "?" + params, true);
httpRequest.send(null);
}
if (method == "POST") {
httpRequest.open(method, url, true);
httpRequest.setRequestHeader("Content-type",
"application/x-www-form-urlencoded");
httpRequest.send(params);
}
}

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,7 @@
function input_show() {
if(document.getElementById("ci").style.display == "none") {
document.getElementById("ci").style.display = "block";
}else{
document.getElementById("ci").style.display = "none";
}
}

78
src/main/webapp/mine.jsp Normal file
View File

@ -0,0 +1,78 @@
<%@ page import="com.dao.IPostDAO" %>
<%@ page import="com.service.PostDAO" %>
<%@ page import="java.util.List" %>
<%@ page import="com.bean.Post" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%--
Created by IntelliJ IDEA.
User: yuex1ng
Date: 2023/12/22
Time: 13:31
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="stylesheet" href="css/universal.css" />
<link rel="stylesheet" href="css/about.css" />
<link rel="stylesheet" href="css/mine.css" />
<title>FORUM</title>
<link rel="icon" href="images/moon.png" type="image/x-icon" />
</head>
<body>
<div class="header">
<h1>FORUM</h1>
<p>Everyone loves something.</p>
</div>
<div class="topnav">
<ul>
<li><a href="home.jsp">首页</a></li>
<li><a href="mine.jsp">我的</a></li>
<li><a href="publish.html">发帖</a></li>
<li><a href="home_login.jsp">账号</a></li>
<li><a href="about.html">关于</a></li>
</ul>
</div>
<div class="row">
<div class="card">
<h3>我的贴子</h3>
<br>
<%
String author = (String) session.getAttribute("username_session");
IPostDAO iPostDAO = new PostDAO();
List<Post> posts = null;
try {
posts = iPostDAO.findByAuthor(author);
} catch (Exception e) {
e.printStackTrace();
}
assert posts != null;
for (Post post : posts) { %>
<form action="./post.jsp" method="post" id="form<%=post.getId()%>">
<label>
<input type="text" name="id" value="<%=post.getId()%>">
</label>
<div class="posta"><a href="" onclick="document.getElementById('form<%=post.getId()%>').submit();return false;"><%=post.getTitle()%></a></div>
</form>
<%
}
%>
</div>
</div>
<div class="footer">
<h2>Everyone loves something.</h2>
</div>
</body>
</html>

126
src/main/webapp/post.jsp Normal file
View File

@ -0,0 +1,126 @@
<%@ page import="com.dao.IPostDAO" %>
<%@ page import="com.service.PostDAO" %>
<%@ page import="com.bean.Post" %>
<%@ page import="com.service.CommentDAO" %>
<%@ page import="com.dao.iCommentDAO" %>
<%@ page import="java.util.List" %>
<%@ page import="com.bean.Comment" %>
<%--
Created by IntelliJ IDEA.
User: yuex1ng
Date: 2023/12/23
Time: 14:52
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8"%>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="stylesheet" href="css/universal.css" />
<link rel="stylesheet" href="css/about.css" />
<link rel="stylesheet" href="css/post.css" />
<script src="js/post.js"></script>
<title>FORUM</title>
<link rel="icon" href="images/moon.png" type="image/x-icon" />
</head>
<body>
<div class="header">
<h1>FORUM</h1>
<p>Everyone loves something.</p>
</div>
<div class="topnav">
<ul>
<li><a href="home.jsp">首页</a></li>
<li><a href="mine.jsp">我的</a></li>
<li><a href="publish.html">发帖</a></li>
<li><a href="home_login.jsp">账号</a></li>
<li><a href="about.html">关于</a></li>
</ul>
</div>
<div class="row">
<div class="card">
<%
int id = Integer.parseInt(request.getParameter("id"));
IPostDAO iPostDAO = new PostDAO();
Post post = new Post();
post.setId(id);
Post post1 = null;
try {
post1 = iPostDAO.findById(post);
} catch (Exception e) {
e.printStackTrace();
}
assert post1 != null;%>
<h3><%=post1.getTitle()%></h3>
<div class="ifmt">
<div class="author">
<p>作者:<%=post1.getAuthor()%></p>
</div>
<div class="type">
<p>类型:<%=post1.getType()%></p>
</div>
<div class="date">
<p>时间:<%=post1.getDate()%></p>
</div>
</div>
<div class="content">
<%=post1.getContent()%>
</div>
</div>
<div class="card comment">
<hr>
<div class="title">
<div class="text">
<h3>评论</h3>
</div>
<div class="btn">
<button onclick="input_show()">+</button>
</div>
</div><br>
<div class="cinput" id="ci" style="display: none;">
<form action="CommentAdd" method="post">
<input type="text" id="content" name="content">
<input style="display: none" type="text" id="post_id" name="post_id" value="<%=post1.getId()%>">
<div class="btn">
<button type="submit">评论</button>
</div>
</form>
</div>
<br>
<div class="comments">
<%
iCommentDAO icommentdao = new CommentDAO();
List<Comment> comments = null;
try {
comments = icommentdao.findByPostId(post1);
} catch (Exception e) {
e.printStackTrace();
}
assert comments != null;
for (Comment comment : comments) {
%>
<h5><%=comment.getAuthor()%> : <%=comment.getContent()%></h5>
<br>
<%
}
%>
</div>
</div>
</div>
<div class="footer">
<h2>Everyone loves something.</h2>
</div>
</body>
</html>

View File

@ -0,0 +1,64 @@
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="stylesheet" href="css/universal.css" />
<link rel="stylesheet" href="css/about.css" />
<link rel="stylesheet" href="css/publish.css" />
<title>FORUM</title>
<link rel="icon" href="images/moon.png" type="image/x-icon" />
</head>
<body>
<div class="header">
<h1>FORUM</h1>
<p>Everyone loves something.</p>
</div>
<div class="topnav">
<ul>
<li><a href="home.jsp">首页</a></li>
<li><a href="mine.jsp">我的</a></li>
<li><a href="publish.html">发帖</a></li>
<li><a href="home_login.jsp">账号</a></li>
<li><a href="about.html">关于</a></li>
</ul>
</div>
<div class="row">
<div class="card">
<h3>编辑</h3>
<br>
<div class="edit">
<form action="/PostWrite" method="POST">
<br>
<label>贴子标题:<input type="text" name="title"></label>
<br><br>
<label>贴子类型:
<input type="radio" id="new" name="ntype" value="学习讨论">
<label for="new">学习讨论</label>
<input type="radio" id="money" name="ntype" value="校园生活">
<label for="money">校园生活</label>
<input type="radio" id="intnl" name="ntype" value="表白墙">
<label for="intnl">表白墙</label>
</label>
<br><br>
<label>贴子内容:<br>
<textarea rows="10" name="content"></textarea>
</label>
<button type="submit">发布</button>
</form>
</div>
</div>
</div>
<div class="footer">
<h2>Everyone loves something.</h2>
</div>
</body>
</html>

View File

@ -0,0 +1,59 @@
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="stylesheet" href="css/universal.css" />
<link rel="stylesheet" href="css/about.css" />
<link rel="stylesheet" href="css/index.css" />
<link rel="stylesheet" href="css/signup.css" />
<title>FORUM</title>
<link rel="icon" href="images/moon.png" type="image/x-icon" />
</head>
<body>
<div class="header">
<h1>FORUM</h1>
<p>Everyone loves something.</p>
</div>
<div class="topnav">
<ul>
<li><a href="#">首页</a></li>
<li><a href="#">我的</a></li>
<li><a href="#">发帖</a></li>
<li><a href="#">账号</a></li>
<li><a href="#">关于</a></li>
</ul>
</div>
<div class="row">
<div class="card">
<h3>注册</h3>
<br>
<div class="login">
<form action="SignCheck" method="post">
<br>
<label>用户名:<input type="text" name="username"></label>
<br><br>
<label>密 码:<input type="password" name="userpwd"></label>
<br><br>
<label>重 复:<input type="password" name="reuserpwd"></label>
<br><br>
<button type="submit">注册</button>
</form>
</div>
<br>
<a href="./index.html">登录界面</a>
</div>
</div>
<div class="footer">
<h2>Everyone loves something.</h2>
</div>
</body>
</html>

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.