diff --git a/homework8/.idea/MarsCodeWorkspaceAppSettings.xml b/homework8/.idea/MarsCodeWorkspaceAppSettings.xml
new file mode 100644
index 0000000..05ed8ba
--- /dev/null
+++ b/homework8/.idea/MarsCodeWorkspaceAppSettings.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/homework8/.idea/dataSources.xml b/homework8/.idea/dataSources.xml
new file mode 100644
index 0000000..8155b6e
--- /dev/null
+++ b/homework8/.idea/dataSources.xml
@@ -0,0 +1,18 @@
+
+
+
+
+ mysql.8
+ true
+ com.mysql.cj.jdbc.Driver
+ jdbc:mysql://msksbr.com:3306
+
+
+
+
+
+
+ $ProjectFileDir$
+
+
+
\ No newline at end of file
diff --git a/homework8/.idea/encodings.xml b/homework8/.idea/encodings.xml
new file mode 100644
index 0000000..aa00ffa
--- /dev/null
+++ b/homework8/.idea/encodings.xml
@@ -0,0 +1,7 @@
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/homework8/.idea/kotlinc.xml b/homework8/.idea/kotlinc.xml
new file mode 100644
index 0000000..98c459d
--- /dev/null
+++ b/homework8/.idea/kotlinc.xml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/homework8/.idea/misc.xml b/homework8/.idea/misc.xml
index 6ed36dd..132404b 100644
--- a/homework8/.idea/misc.xml
+++ b/homework8/.idea/misc.xml
@@ -1,4 +1,14 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/homework8/.idea/sqldialects.xml b/homework8/.idea/sqldialects.xml
new file mode 100644
index 0000000..5e0d80f
--- /dev/null
+++ b/homework8/.idea/sqldialects.xml
@@ -0,0 +1,7 @@
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/homework8/.idea/vcs.xml b/homework8/.idea/vcs.xml
new file mode 100644
index 0000000..6c0b863
--- /dev/null
+++ b/homework8/.idea/vcs.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/homework8/.idea/webContexts.xml b/homework8/.idea/webContexts.xml
new file mode 100644
index 0000000..5178070
--- /dev/null
+++ b/homework8/.idea/webContexts.xml
@@ -0,0 +1,10 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/homework8/char12.sql b/homework8/char12.sql
new file mode 100644
index 0000000..5f5a1fc
--- /dev/null
+++ b/homework8/char12.sql
@@ -0,0 +1,15 @@
+
+CREATE DATABASE char12;
+
+USE char12;
+
+CREATE TABLE info(
+ id INT PRIMARY KEY,
+ title VARCHAR(255)
+);
+
+INSERT INTO info
+VALUES
+ (1, 'SALES!!'),
+ (2, 'BUY NOW!!'),
+ (3, 'NOT AVAILABLE!!');
\ No newline at end of file
diff --git a/homework8/pom.xml b/homework8/pom.xml
index e533ae1..9a1bb48 100644
--- a/homework8/pom.xml
+++ b/homework8/pom.xml
@@ -18,6 +18,18 @@
+
+
+ com.mysql
+ mysql-connector-j
+ 9.3.0
+
+
+
+ org.yaml
+ snakeyaml
+ 2.4
+
javax.servlet
javax.servlet-api
diff --git a/homework8/src/main/java/com/msksbr/homework8/dao/ConnDB.java b/homework8/src/main/java/com/msksbr/homework8/dao/ConnDB.java
new file mode 100644
index 0000000..99081ca
--- /dev/null
+++ b/homework8/src/main/java/com/msksbr/homework8/dao/ConnDB.java
@@ -0,0 +1,78 @@
+package com.msksbr.homework8.dao;
+
+import org.yaml.snakeyaml.Yaml;
+
+import java.io.InputStream;
+import java.sql.Connection;
+import java.sql.ResultSet;
+import java.sql.Statement;
+import java.util.Map;
+
+public class ConnDB {
+ private static final DBInfo dbInfo = new DBInfo();
+ public Connection conn = null;
+ public Statement stmt = null;
+ public ResultSet rs = null;
+
+ public ConnDB() {
+ try {
+ Class.forName("com.mysql.cj.jdbc.Driver");
+ conn = java.sql.DriverManager.getConnection(dbInfo.getUrl(), dbInfo.username, dbInfo.password);
+ stmt = conn.createStatement();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ public ResultSet executeQuery(String query) {
+ try {
+ rs = this.stmt.executeQuery(query);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ return rs;
+ }
+
+ public void executeUpdate(String query) {
+ try {
+ this.stmt.executeUpdate(query);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ static class DBInfo {
+ String address;
+ String port;
+ String username;
+ String password;
+ String database;
+ String yaml_url = "/dbInfo.yaml";
+
+ public DBInfo() {
+ Map dbInfo = loadYaml();
+ this.address = dbInfo.get("address");
+ this.port = dbInfo.get("port");
+ this.username = dbInfo.get("username");
+ this.password = dbInfo.get("password");
+ this.database = dbInfo.get("database");
+ }
+
+ public Map loadYaml() {
+ Yaml yaml = new Yaml();
+ try (InputStream inputStream = DBInfo.class.getResourceAsStream(yaml_url)) {
+ if (inputStream == null) {
+ throw new RuntimeException("YAML file not found" + yaml_url);
+ }
+ return yaml.load(inputStream);
+ } catch (Exception e) {
+ throw new RuntimeException("Failed to load YAML file", e);
+ }
+ }
+
+ public String getUrl() {
+ String url = "jdbc:mysql://" + this.address + ":" + this.port + "/" + this.database;
+ return url;
+ }
+ }
+}
diff --git a/homework8/src/main/resources/dbInfo sample.yaml b/homework8/src/main/resources/dbInfo sample.yaml
new file mode 100644
index 0000000..b04596c
--- /dev/null
+++ b/homework8/src/main/resources/dbInfo sample.yaml
@@ -0,0 +1,9 @@
+# this is a sample of yaml file for dbInfo.yaml
+# you can change the value of the key to your own value
+# 1. copy this file to the same directory as dbInfo.yaml
+# 2. change the value of the key to your own value
+address: "localhost"
+port: "3306"
+username: "root"
+password: "123456"
+database: "master"
\ No newline at end of file
diff --git a/homework8/src/main/webapp/ajax.jsp b/homework8/src/main/webapp/ajax.jsp
new file mode 100644
index 0000000..8d90f74
--- /dev/null
+++ b/homework8/src/main/webapp/ajax.jsp
@@ -0,0 +1,55 @@
+<%@ page contentType="text/html;charset=UTF-8" language="java" %>
+
+
+ Ajax
+
+
+
+
+
+
+
diff --git a/homework8/src/main/webapp/getInfo.jsp b/homework8/src/main/webapp/getInfo.jsp
new file mode 100644
index 0000000..06b5155
--- /dev/null
+++ b/homework8/src/main/webapp/getInfo.jsp
@@ -0,0 +1,17 @@
+<%@ page language="java" contentType="text/html;charset=UTF-8"
+ pageEncoding="UTF-8" %>
+<%@page import="java.sql.*" %>
+
+
+ <%
+ ResultSet rs=conn.executeQuery("select title from info order by id desc");
+ if(rs.next()){
+ do{
+ out.print("- "+rs.getString(1)+"
");
+ }while (rs.next());
+ }else{
+ out.print("- 暂无公告信息!
");
+ }
+ %>
+
diff --git a/homework8/src/main/webapp/index.jsp b/homework8/src/main/webapp/index.jsp
index dd88878..8517399 100644
--- a/homework8/src/main/webapp/index.jsp
+++ b/homework8/src/main/webapp/index.jsp
@@ -1,13 +1,26 @@
-<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
-
+<%@ page contentType="text/html;charset=UTF-8" language="java" %>
- JSP - Hello World
+ index
+
+
-<%= "Hello World!" %>
-
-
-Hello Servlet
+
-
\ No newline at end of file
+