archieve: homework8
This commit is contained in:
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="com.codeverse.userSettings.MarscodeWorkspaceAppSettingsState">
|
||||
<option name="ckgOperationStatus" value="SUCCESS" />
|
||||
</component>
|
||||
</project>
|
||||
Generated
+18
@@ -0,0 +1,18 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="DataSourceManagerImpl" format="xml" multifile-model="true">
|
||||
<data-source source="LOCAL" name="@msksbr.com" uuid="9dde1f7f-e832-46cc-b676-a153d5b8635d">
|
||||
<driver-ref>mysql.8</driver-ref>
|
||||
<synchronize>true</synchronize>
|
||||
<jdbc-driver>com.mysql.cj.jdbc.Driver</jdbc-driver>
|
||||
<jdbc-url>jdbc:mysql://msksbr.com:3306</jdbc-url>
|
||||
<jdbc-additional-properties>
|
||||
<property name="com.intellij.clouds.kubernetes.db.host.port" />
|
||||
<property name="com.intellij.clouds.kubernetes.db.enabled" value="false" />
|
||||
<property name="com.intellij.clouds.kubernetes.db.resource.type" value="Deployment" />
|
||||
<property name="com.intellij.clouds.kubernetes.db.container.port" />
|
||||
</jdbc-additional-properties>
|
||||
<working-dir>$ProjectFileDir$</working-dir>
|
||||
</data-source>
|
||||
</component>
|
||||
</project>
|
||||
Generated
+7
@@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="Encoding">
|
||||
<file url="file://$PROJECT_DIR$/src/main/java" charset="UTF-8" />
|
||||
<file url="file://$PROJECT_DIR$/src/main/resources" charset="UTF-8" />
|
||||
</component>
|
||||
</project>
|
||||
Generated
+13
@@ -0,0 +1,13 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="Kotlin2JsCompilerArguments">
|
||||
<option name="moduleKind" value="plain" />
|
||||
</component>
|
||||
<component name="Kotlin2JvmCompilerArguments">
|
||||
<option name="jvmTarget" value="1.8" />
|
||||
</component>
|
||||
<component name="KotlinCommonCompilerArguments">
|
||||
<option name="apiVersion" value="2.1" />
|
||||
<option name="languageVersion" value="2.1" />
|
||||
</component>
|
||||
</project>
|
||||
Generated
+10
@@ -1,4 +1,14 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ExternalStorageConfigurationManager" enabled="true" />
|
||||
<component name="MavenProjectsManager">
|
||||
<option name="originalFiles">
|
||||
<list>
|
||||
<option value="$PROJECT_DIR$/pom.xml" />
|
||||
</list>
|
||||
</option>
|
||||
</component>
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/out" />
|
||||
</component>
|
||||
</project>
|
||||
Generated
+7
@@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="SqlDialectMappings">
|
||||
<file url="file://$PROJECT_DIR$/char12.sql" dialect="MySQL" />
|
||||
<file url="PROJECT" dialect="MySQL" />
|
||||
</component>
|
||||
</project>
|
||||
Generated
+6
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="$PROJECT_DIR$/.." vcs="Git" />
|
||||
</component>
|
||||
</project>
|
||||
Generated
+10
@@ -0,0 +1,10 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="WebContextManager">
|
||||
<option name="state">
|
||||
<map>
|
||||
<entry key="file://$PROJECT_DIR$/src/main/webapp/getInfo.jsp" value="file://$PROJECT_DIR$/src/main/webapp" />
|
||||
</map>
|
||||
</option>
|
||||
</component>
|
||||
</project>
|
||||
@@ -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!!');
|
||||
@@ -18,6 +18,18 @@
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<!-- https://mvnrepository.com/artifact/com.mysql/mysql-connector-j -->
|
||||
<dependency>
|
||||
<groupId>com.mysql</groupId>
|
||||
<artifactId>mysql-connector-j</artifactId>
|
||||
<version>9.3.0</version>
|
||||
</dependency>
|
||||
<!-- https://mvnrepository.com/artifact/org.yaml/snakeyaml -->
|
||||
<dependency>
|
||||
<groupId>org.yaml</groupId>
|
||||
<artifactId>snakeyaml</artifactId>
|
||||
<version>2.4</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>javax.servlet</groupId>
|
||||
<artifactId>javax.servlet-api</artifactId>
|
||||
|
||||
@@ -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<String, String> 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<String, String> 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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"
|
||||
@@ -0,0 +1,55 @@
|
||||
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
|
||||
<html>
|
||||
<head>
|
||||
<title>Ajax</title>
|
||||
<script type="text/javascript"
|
||||
src="${pageContext.request.contextPath}/jquery-3.6.0.js"></script>
|
||||
<script type="text/javascript">
|
||||
$(document).ready(function(){
|
||||
$("button").click(function(){
|
||||
$.ajax({
|
||||
type:"post", //提交方式
|
||||
url:'${pageContext.request.contextPath}/AJAXServlet',
|
||||
data:{
|
||||
userName: $("#userName").val(),
|
||||
password: $("#password").val()
|
||||
}, //data中的内容会自动的添加到url后面
|
||||
dataType: "text", //返回数据的格式
|
||||
success:function(a){ //请求成功后执行的函数
|
||||
if(a=="true"){
|
||||
$('#suss').html("登录成功!")
|
||||
}else{
|
||||
$('#suss').html("登录失败!")
|
||||
}
|
||||
},
|
||||
error :function () { //请求失败后执行的函数
|
||||
alert("请求失败");
|
||||
},
|
||||
});
|
||||
});
|
||||
});
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
<div>
|
||||
<div>
|
||||
<ul>
|
||||
<li>用户名:</li>
|
||||
<li><input id="userName" name="userName" type="text" /></li>
|
||||
</ul>
|
||||
</div>
|
||||
<div>
|
||||
<ul>
|
||||
<li>密码:</li>
|
||||
<li><input id="password" name="password" type="password"/></li>
|
||||
</ul>
|
||||
</div>
|
||||
<div>
|
||||
<ul>
|
||||
<li><button>登录</button></li>
|
||||
</ul>
|
||||
</div>
|
||||
<div id="suss"></div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,17 @@
|
||||
<%@ page language="java" contentType="text/html;charset=UTF-8"
|
||||
pageEncoding="UTF-8" %>
|
||||
<%@page import="java.sql.*" %>
|
||||
<jsp:useBean id="conn" class="com.msksbr.homework8.dao.ConnDB"
|
||||
scope="page"></jsp:useBean>
|
||||
<ul>
|
||||
<%
|
||||
ResultSet rs=conn.executeQuery("select title from info order by id desc");
|
||||
if(rs.next()){
|
||||
do{
|
||||
out.print("<li>"+rs.getString(1)+"</li>");
|
||||
}while (rs.next());
|
||||
}else{
|
||||
out.print("<li>暂无公告信息!</li>");
|
||||
}
|
||||
%>
|
||||
</ul>
|
||||
@@ -1,13 +1,26 @@
|
||||
<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
|
||||
<!DOCTYPE html>
|
||||
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
|
||||
<html>
|
||||
<head>
|
||||
<title>JSP - Hello World</title>
|
||||
<title>index</title>
|
||||
<script type="text/javascript"
|
||||
src="${pageContext.request.contextPath}/jquery-3.6.0.js"></script>
|
||||
<script language="JavaScript">
|
||||
function getInfo() {
|
||||
$.get("${pageContext.request.contextPath}/getInfo.jsp?nocache=" + new Date().getTime(), function (data) {
|
||||
$("#showInfo").html(data);
|
||||
});
|
||||
}
|
||||
|
||||
$(document).ready(function () {
|
||||
getInfo();//调用getInfo()方法获取公告信息
|
||||
window.setInterval("getInfo()", 600000);
|
||||
})
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
<h1><%= "Hello World!" %>
|
||||
</h1>
|
||||
<br/>
|
||||
<a href="hello-servlet">Hello Servlet</a>
|
||||
<section>
|
||||
<marquee id="showInfo" direction="up" scrollamount="3">
|
||||
</marquee>
|
||||
</section>
|
||||
</body>
|
||||
</html>
|
||||
</html>
|
||||
|
||||
+10881
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user