From fb4b70abdbf1ca93c86275dfb28fda46da7751cf Mon Sep 17 00:00:00 2001
From: WangTingZheng <2251985371@qq.com>
Date: Tue, 14 Jul 2020 13:23:56 +0800
Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E6=AD=A3=E6=89=BE=E4=B8=8D?=
=?UTF-8?q?=E5=88=B0action=E7=9A=84=E9=97=AE=E9=A2=98?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
原因:struct.xml的位置不正确,不应该放在外面的(根目录)src里而是需要在web模块下新建一个src文件夹,把它标记为source
文件夹,然后把所有的Java包和struct.xml文件移动到这个目录下
修正:
1.在web模块下新建一个src文件夹并标记为source
root
2.移动/src/guoyachen到/web/src/guoyachen
3.移动/src/struct.xml到/web/src/struct.xml
4.在file-project structure下的artifact里,在web-inf下新建lib文件夹存放jar包,右键点击avaliable elements下的条目,选择put into output root,记住,如果发现有找不到class的报错,重复次步骤即可,同时清除web-inf页面下的lib文件夹里有标红的jar
5.在file-project structure下的facets选项中,选择struct2,在右边点击铅笔图标,重新选择struct.xml的位置,具体的看这篇文章:https://www.jianshu.com/p/3a2ca7ee6b82
6.在pom.xml下条件build模块,强行规定jdk版本为1.8,修复由于依赖变动导致的jdk版本的错乱
7.添加${pageContext.request.contextPath}/到register.jsp下的action地址上
---
.../WebPage_Client_Test_war_exploded.xml | 20 ++++++
.idea/compiler.xml | 2 +-
WebPage_Client_Test.iml | 10 +--
pom.xml | 16 +++++
.../WebPage_Client_Test.kotlin_module | Bin 16 -> 0 bytes
src/main/java/guoyachen/mvc/Register.java | 61 -----------------
src/main/java/guoyachen/mvc/dao/UserDAO.java | 12 ----
.../mvc/dao/implement/UserDAOImpl.java | 55 ---------------
.../guoyachen/mvc/dao/proxy/UserDAOProxy.java | 39 -----------
.../guoyachen/mvc/dbc/DatabaseConnection.java | 37 ----------
.../guoyachen/mvc/factory/DAOFactory.java | 16 -----
.../guoyachen/mvc/servlet/LoginServlet.java | 64 ------------------
src/main/java/guoyachen/mvc/vo/User.java | 31 ---------
.../guoyachen/spring/DemoApplication.java | 9 ---
src/main/resources/applicationcontext.xml | 7 --
src/struts.xml | 20 ------
web/register.jsp | 3 +-
17 files changed, 45 insertions(+), 357 deletions(-)
delete mode 100644 src/main/java/META-INF/WebPage_Client_Test.kotlin_module
delete mode 100644 src/main/java/guoyachen/mvc/Register.java
delete mode 100644 src/main/java/guoyachen/mvc/dao/UserDAO.java
delete mode 100644 src/main/java/guoyachen/mvc/dao/implement/UserDAOImpl.java
delete mode 100644 src/main/java/guoyachen/mvc/dao/proxy/UserDAOProxy.java
delete mode 100644 src/main/java/guoyachen/mvc/dbc/DatabaseConnection.java
delete mode 100644 src/main/java/guoyachen/mvc/factory/DAOFactory.java
delete mode 100644 src/main/java/guoyachen/mvc/servlet/LoginServlet.java
delete mode 100644 src/main/java/guoyachen/mvc/vo/User.java
delete mode 100644 src/main/java/guoyachen/spring/DemoApplication.java
delete mode 100644 src/main/resources/applicationcontext.xml
delete mode 100644 src/struts.xml
diff --git a/.idea/artifacts/WebPage_Client_Test_war_exploded.xml b/.idea/artifacts/WebPage_Client_Test_war_exploded.xml
index c8984cf..c4a38d5 100644
--- a/.idea/artifacts/WebPage_Client_Test_war_exploded.xml
+++ b/.idea/artifacts/WebPage_Client_Test_war_exploded.xml
@@ -7,6 +7,26 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/.idea/compiler.xml b/.idea/compiler.xml
index 9ed0716..1d0532b 100644
--- a/.idea/compiler.xml
+++ b/.idea/compiler.xml
@@ -10,7 +10,7 @@
-
+
\ No newline at end of file
diff --git a/WebPage_Client_Test.iml b/WebPage_Client_Test.iml
index 4a07f57..5bde2c6 100644
--- a/WebPage_Client_Test.iml
+++ b/WebPage_Client_Test.iml
@@ -11,13 +11,14 @@
-
- file://$MODULE_DIR$/src/struts.xml
+ file://$MODULE_DIR$/web/src/struts.xml
+ file://$MODULE_DIR$/web/src/struts.xml
+ jar://$MODULE_DIR$/web/WEB-INF/lib/struts2-core-2.5.22.jar!/struts-default.xml
@@ -32,13 +33,14 @@
-
+
-
+
+
diff --git a/pom.xml b/pom.xml
index d6a9cd7..0a69b8d 100644
--- a/pom.xml
+++ b/pom.xml
@@ -9,6 +9,22 @@
1.0-SNAPSHOT
+
+
+
+ org.apache.maven.plugins
+ maven-compiler-plugin
+ 3.1
+
+ 1.8
+ 1.8
+ UTF-8
+
+
+
+
+
+
diff --git a/src/main/java/META-INF/WebPage_Client_Test.kotlin_module b/src/main/java/META-INF/WebPage_Client_Test.kotlin_module
deleted file mode 100644
index a49347afef10a9b5f95305e1058ba36adec7d6dd..0000000000000000000000000000000000000000
GIT binary patch
literal 0
HcmV?d00001
literal 16
RcmZQzU|?ooU|@t|0RRA102TlM
diff --git a/src/main/java/guoyachen/mvc/Register.java b/src/main/java/guoyachen/mvc/Register.java
deleted file mode 100644
index 3d43b1c..0000000
--- a/src/main/java/guoyachen/mvc/Register.java
+++ /dev/null
@@ -1,61 +0,0 @@
-package guoyachen.mvc;
-
-import com.opensymphony.xwork2.ActionSupport;
-import guoyachen.mvc.dbc.DatabaseConnection;
-import guoyachen.mvc.vo.User;
-
-import java.sql.Connection;
-import java.sql.PreparedStatement;
-
-/**
- * @Author:Guo Yachen
- * @Date:2020/7/14 2:14
- * @Description:
- * @Feature:
- */
-public class Register extends ActionSupport {
-
-
- private String username;
- private String password;
- Connection conn;
- PreparedStatement prep;
-
-
- public void setUsername(String username) {
- this.username = username;
- }
-
- public void setPassword(String password) {
- this.password = password;
- }
-
-
-
- public String execute() throws Exception
- {
-
- return "success";
-// try {
-// conn = (Connection) new DatabaseConnection();
-// String sql = "INSERT INTO test_table (user,password) VALUES('"+user.getUsername()+"','"+user.getPassword()+"');";
-// System.out.print(sql);
-// prep = conn.prepareStatement(sql);
-// int result = prep.executeUpdate();
-//
-// if(result >0)
-// {
-// return "success";
-// }
-// else
-// {
-// return "error";
-// }
-//
-// } catch (Exception e) {
-// e.printStackTrace();
-// }
-//
-// return"error";
- }
-}
diff --git a/src/main/java/guoyachen/mvc/dao/UserDAO.java b/src/main/java/guoyachen/mvc/dao/UserDAO.java
deleted file mode 100644
index 41a6865..0000000
--- a/src/main/java/guoyachen/mvc/dao/UserDAO.java
+++ /dev/null
@@ -1,12 +0,0 @@
-package guoyachen.mvc.dao;
-import guoyachen.mvc.vo.User;
-/**
- * @Author:Guo Yachen
- * @Date:2020/7/11 12:36
- * @Description:
- * @Feature:
- */
-public interface UserDAO {
-
- public boolean findLogin(User user) throws Exception;
-}
diff --git a/src/main/java/guoyachen/mvc/dao/implement/UserDAOImpl.java b/src/main/java/guoyachen/mvc/dao/implement/UserDAOImpl.java
deleted file mode 100644
index 0861584..0000000
--- a/src/main/java/guoyachen/mvc/dao/implement/UserDAOImpl.java
+++ /dev/null
@@ -1,55 +0,0 @@
-package guoyachen.mvc.dao.implement;
-
-import java.sql.Connection;
-import java.sql.PreparedStatement;
-import java.sql.ResultSet;
-
-import guoyachen.mvc.dao.UserDAO;
-import guoyachen.mvc.vo.User;
-
-/**
- * @Author:Guo Yachen
- * @Date:2020/7/11 12:37
- * @Description:
- * @Feature:
- */
-public class UserDAOImpl implements UserDAO {
-
- private Connection conn = null;
- private PreparedStatement pstmt = null;
-
-
- public UserDAOImpl(Connection conn) {
- this.conn = conn;
- }
-
-
- public boolean findLogin(User user) throws Exception {
-
- boolean flag = false;
-
-
- String sql = "SELECT user FROM test_table WHERE user='"+user.getUsername()+"' AND password='"+user.getPassword()+"';";
- System.out.print(sql);
- this.pstmt = this.conn.prepareStatement(sql);
-// this.pstmt.setString(1, user.getUsername());
-// this.pstmt.setString(2, user.getPassword());
-
- ResultSet rs = this.pstmt.executeQuery();
-
- if (rs.next()) {
-
- flag = true;
- }
-
- if (this.pstmt != null) {
- this.pstmt.close();
- }
-
-
- System.out.print(flag);
- return flag;
- }
-
-
-}
\ No newline at end of file
diff --git a/src/main/java/guoyachen/mvc/dao/proxy/UserDAOProxy.java b/src/main/java/guoyachen/mvc/dao/proxy/UserDAOProxy.java
deleted file mode 100644
index 08456fd..0000000
--- a/src/main/java/guoyachen/mvc/dao/proxy/UserDAOProxy.java
+++ /dev/null
@@ -1,39 +0,0 @@
-package guoyachen.mvc.dao.proxy;
-
-import guoyachen.mvc.dao.UserDAO;
-import guoyachen.mvc.dao.implement.UserDAOImpl;
-import guoyachen.mvc.dbc.DatabaseConnection;
-import guoyachen.mvc.vo.User;
-
-/**
- * @Author:Guo Yachen
- * @Date:2020/7/11 13:13
- * @Description:
- * @Feature:
- */
-public class UserDAOProxy implements UserDAO {
-
- private DatabaseConnection dbc = null;
- private UserDAO dao = null;
-
- public UserDAOProxy()
- {
- try {
- this.dbc = new DatabaseConnection();
- } catch (Exception e) {
- e.printStackTrace();
- }
-
- this.dao = new UserDAOImpl(this.dbc.getConnection());
- }
-
- public boolean findLogin(User user) throws Exception {
- boolean flag = false;
-
- flag = this.dao.findLogin(user);
-
- this.dbc.close();
-
- return flag;
- }
-}
diff --git a/src/main/java/guoyachen/mvc/dbc/DatabaseConnection.java b/src/main/java/guoyachen/mvc/dbc/DatabaseConnection.java
deleted file mode 100644
index eaac69d..0000000
--- a/src/main/java/guoyachen/mvc/dbc/DatabaseConnection.java
+++ /dev/null
@@ -1,37 +0,0 @@
-package guoyachen.mvc.dbc;
-
-import com.mysql.cj.jdbc.Driver;
-import java.sql.Connection;
-import java.sql.DriverManager;
-
-/**
- * @Author:Guo Yachen
- * @Date:2020/7/11 12:28
- * @Description:数据库连接
- * @Feature:
- */
-public class DatabaseConnection {
-
- private static final String DBDRIVER="com.mysql.cj.jdbc.Driver";
- private static final String DBURL="jdbc:mysql://localhost:3306/DatabaseForTest?serverTimezone=UTC";
- private static final String DBUSER="root";
- private static final String DBPASSWORD="root";
-
- private Connection conn = null;
-
- public DatabaseConnection() throws Exception{
- Class.forName(DBDRIVER);
- this.conn = DriverManager.getConnection(DBURL,DBUSER,DBPASSWORD);
-
- }
-
- public Connection getConnection(){
- return this.conn;
- }
-
- public void close() throws Exception{
- if(this.conn != null){
- this.conn.close();
- }
- }
-}
diff --git a/src/main/java/guoyachen/mvc/factory/DAOFactory.java b/src/main/java/guoyachen/mvc/factory/DAOFactory.java
deleted file mode 100644
index fa780ae..0000000
--- a/src/main/java/guoyachen/mvc/factory/DAOFactory.java
+++ /dev/null
@@ -1,16 +0,0 @@
-package guoyachen.mvc.factory;
-
-import guoyachen.mvc.dao.UserDAO;
-import guoyachen.mvc.dao.proxy.UserDAOProxy;
-
-/**
- * @Author:Guo Yachen
- * @Date:2020/7/11 13:16
- * @Description:
- * @Feature:
- */
-public class DAOFactory {
- public static UserDAO getUserDAOInstance(){
- return new UserDAOProxy();
- }
-}
diff --git a/src/main/java/guoyachen/mvc/servlet/LoginServlet.java b/src/main/java/guoyachen/mvc/servlet/LoginServlet.java
deleted file mode 100644
index 5897512..0000000
--- a/src/main/java/guoyachen/mvc/servlet/LoginServlet.java
+++ /dev/null
@@ -1,64 +0,0 @@
-package guoyachen.mvc.servlet;
-
-
-import guoyachen.mvc.factory.DAOFactory;
-import guoyachen.mvc.vo.User;
-import org.springframework.context.ApplicationContext;
-import org.springframework.context.support.ClassPathXmlApplicationContext;
-
-import javax.servlet.http.HttpServlet;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-import java.io.PrintWriter;
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- * @Author:Guo Yachen
- * @Date:2020/7/11 15:20
- * @Description:
- * @Feature:
- */
-
-public class LoginServlet extends HttpServlet {
- public void doPost(HttpServletRequest req, HttpServletResponse resp)
- {
- String path = "index.jsp";
- String username = req.getParameter("username");
- String password = req.getParameter("password");
-
- List info = new ArrayList();
-
- User user = new User();
- user.setUsername(username);
- user.setPassword(password);
-
- try {
- //这三个一定要在输出流之前
- req.setCharacterEncoding("utf-8");
- resp.setContentType("text/html;charset=utf-8");
- resp.setCharacterEncoding("utf-8");
-
- PrintWriter out = resp.getWriter();
-
- ApplicationContext context = new ClassPathXmlApplicationContext("applicationcontext.xml");
-
- DAOFactory Factory =(DAOFactory) context.getBean("Factory");
-
- if(DAOFactory.getUserDAOInstance().findLogin(user))
- {
-
- out.print("");
- }
- else
- {
-
- out.print("");
- }
-
-
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
-}
diff --git a/src/main/java/guoyachen/mvc/vo/User.java b/src/main/java/guoyachen/mvc/vo/User.java
deleted file mode 100644
index cd327ed..0000000
--- a/src/main/java/guoyachen/mvc/vo/User.java
+++ /dev/null
@@ -1,31 +0,0 @@
-package guoyachen.mvc.vo;
-
-/**
- * @Author:Guo Yachen
- * @Date:2020/7/11 11:14
- * @Description:VO,值对象,用于值的传递操作
- * @Feature:
- */
-public class User {
- private String username;
- private String password;
-
- public String getUsername() {
- return username;
- }
-
- public void setUsername(String username) {
- this.username = username;
- }
-
- public String getPassword() {
- return password;
- }
-
- public void setPassword(String password) {
- this.password = password;
- }
-
-
-
-}
diff --git a/src/main/java/guoyachen/spring/DemoApplication.java b/src/main/java/guoyachen/spring/DemoApplication.java
deleted file mode 100644
index 9c15a7a..0000000
--- a/src/main/java/guoyachen/spring/DemoApplication.java
+++ /dev/null
@@ -1,9 +0,0 @@
-package guoyachen.spring;
-
-/**
- * @Author:Guo Yachen
- * @Date:2020/7/13 14:25
- * @Description:
- * @Feature:
- */
-
diff --git a/src/main/resources/applicationcontext.xml b/src/main/resources/applicationcontext.xml
deleted file mode 100644
index a768715..0000000
--- a/src/main/resources/applicationcontext.xml
+++ /dev/null
@@ -1,7 +0,0 @@
-
-
-
-
-
\ No newline at end of file
diff --git a/src/struts.xml b/src/struts.xml
deleted file mode 100644
index 49bef93..0000000
--- a/src/struts.xml
+++ /dev/null
@@ -1,20 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/web/register.jsp b/web/register.jsp
index 25cd950..a4bae25 100644
--- a/web/register.jsp
+++ b/web/register.jsp
@@ -1,3 +1,4 @@
+<%@ taglib prefix="s" uri="/struts-tags" %>
<%--
Created by IntelliJ IDEA.
User: Yache
@@ -28,7 +29,7 @@