文章目錄
- 一,SQL攻擊
- --1,模擬SQL攻擊的現象
- --2,解決方案
- --3,練習PreparedStatement
- --4,擴展: 程式優化
- 1,創建工具類
- 2,改造測驗類
- 3,總結
- 二,HTML
- --1,概述
- --2,入門案例
- 三,HTML的常見標簽
- --1,概述
- --2,標題,串列,圖片標簽
- --3,超鏈接,輸入框標簽
- --4,表格標簽
- 四,作業
一,SQL攻擊
–1,模擬SQL攻擊的現象
//出現了問題:SQL攻擊:
//1,本質上就是因為SQL中出現了特殊符號#,#號在SQL中是注釋的意思(測驗時使用固定的用戶名jack’#)
//2,Statement傳輸器在執行SQL時遇到了SQL拼接,把#當做了注釋用!!
package cn.tedu.jdbc;
import org.junit.Test;
import java.awt.*;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.Scanner;
//模擬用戶登錄
public class Test2 {
//模擬用戶登錄,從單元測驗改成main()原因是IDEA單元測驗方法無法鍵盤輸入
public static void main(String[] args) throws Exception{
//1,注冊驅動
Class.forName("com.mysql.jdbc.Driver");
//2,連接資料庫
String url="jdbc:mysql:///cgb2109?characterEncoding=utf8";
Connection c = DriverManager.getConnection(url, "root", "root");
//3,獲取傳輸器
Statement s = c.createStatement();
//4,執行SQL
System.out.println("請輸入用戶名:");
String username = new Scanner(System.in).nextLine();
System.out.println("請輸入密碼:");
String password = new Scanner(System.in).nextLine();
//拼接字串: 一對兒雙引號中間一對兒加號 再中間看你了 "+???+"
// String sql="select * from user where name='jack' and pwd='123'";
String sql="select * from user where name='"+username+"' and pwd='"+password+"'";
ResultSet r = s.executeQuery(sql);
//5,處理結果
if( r.next() ){//判斷有資料嗎?如果有資料就可以登錄
System.out.println("登錄成功!");
}else{//沒資料,重新輸入或去注冊
System.out.println("登錄失敗,請重新輸入或去注冊!");
}
//6,釋放資源
r.close();
s.close();
c.close();
}
}
–2,解決方案
package cn.tedu.jdbc;
import org.junit.Test;
import java.awt.*;
import java.sql.*;
import java.util.Scanner;
//模擬用戶登錄
public class Test2 {
//解決了問題:SQL攻擊:
//1,本質上就是因為SQL中出現了特殊符號#,當普通字符用而不是注釋
//2,PreparedStatement 傳輸器在執行SQL時遇到了SQL拼接時直接寫?占位符
//PreparedStatement好處:SQL簡單,安全(解決SQL攻擊),高效
//模擬用戶登錄,從單元測驗改成main()原因是IDEA單元測驗方法無法鍵盤輸入
public static void main(String[] args) throws Exception{
//1,注冊驅動
Class.forName("com.mysql.jdbc.Driver");
//2,連接資料庫
String url="jdbc:mysql:///cgb2109?characterEncoding=utf8";
Connection c = DriverManager.getConnection(url, "root", "root");
//3,獲取傳輸器
// Statement s = c.createStatement();//SQL攻擊問題
//4,執行SQL
System.out.println("請輸入用戶名:");
String username = new Scanner(System.in).nextLine();
System.out.println("請輸入密碼:");
String password = new Scanner(System.in).nextLine();
// String sql="select * from user where name='"+username+"' and pwd='"+password+"'";
//SQL骨架,?叫占位符
String sql="select * from user where name=? and pwd=?";
//準備執行預編譯的SQL
//PreparedStatement好處:SQL簡單,安全(解決SQL攻擊),高效
PreparedStatement s = c.prepareStatement(sql);
//設定SQL中的引數
s.setObject(1,username);//給第1個?設定用戶名
s.setObject(2,password);//給第2個?設定用戶名
ResultSet r = s.executeQuery();
//5,處理結果
if( r.next() ){//判斷有資料嗎?如果有資料就可以登錄
System.out.println("登錄成功!");
}else{//沒資料,重新輸入或去注冊
System.out.println("登錄失敗,請重新輸入或去注冊!");
}
//6,釋放資源
r.close();
s.close();
c.close();
}
}
–3,練習PreparedStatement
package cn.tedu.jdbc;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
//需求:利用新的傳輸器,向dept表里插入資料
public class Test3 {
public static void main(String[] args) throws Exception{
//1,注冊驅動
Class.forName("com.mysql.jdbc.Driver");
//2,獲取連接
String url="jdbc:mysql://localhost:3306/cgb2109?characterEncoding=utf8";
Connection c = DriverManager.getConnection(url, "root", "root");
//3,傳輸器
String sql ="insert into dept values(null,?,?)";//SQL骨架
PreparedStatement p = c.prepareStatement(sql);
//設定SQL中的引數--給第幾個?設定啥值
p.setObject(1,"php開發部");
p.setObject(2,"北京");
//4,執行SQL
p.executeUpdate();//執行增刪改的SQL,回傳影響行數
//5,處理結果
//6,釋放資源
p.close();
c.close();
}
}
–4,擴展: 程式優化
JDBC的前兩步,重復的寫了很多次,優化這種現象來提高代碼的復用性/高內聚.
1,創建工具類
1,提供工具類
2,提供方法(封裝JDBC的前兩步)
package cn.tedu.jdbc;
import java.sql.Connection;
import java.sql.DriverManager;
//封裝了注冊驅動,獲取連接.
//目的:獲取連接,并回傳給呼叫者
public class JDBCUtils {
/**目的:獲取連接,并回傳給呼叫者 */
static public Connection get() throws Exception{
//1,注冊驅動
Class.forName("com.mysql.jdbc.Driver");
//2,獲取連接
String url="jdbc:mysql://localhost:3306/cgb2109?characterEncoding=utf8";
Connection c = DriverManager.getConnection(url, "root", "root");
return c; //回傳給呼叫者
}
}
2,改造測驗類
3,呼叫類里的方法
package cn.tedu.jdbc;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
//需求:利用新的傳輸器,向dept表里插入資料
public class Test3 {
public static void main(String[] args) throws Exception{
//TODO 利用工具類里封裝好的方法
Connection c = JDBCUtils.get();
//3,傳輸器
String sql ="insert into dept values(null,?,?)";//SQL骨架
PreparedStatement p = c.prepareStatement(sql);
//設定SQL中的引數--給第幾個?設定啥值
p.setObject(1,"php開發部");
p.setObject(2,"北京");
//4,執行SQL
p.executeUpdate();//執行增刪改的SQL,回傳影響行數
//5,處理結果
//6,釋放資源
c.close();
p.close();
}
}
3,總結

二,HTML
–1,概述
是超文本標記語言.
網頁中的元素型別可以超過文本內容
標記語言: HTML中提供了大量標記/標簽,開始標簽和結束標簽
–2,入門案例
1,右鍵-新建專案-輸入專案名稱-創建
2,右鍵-新建-HTML檔案-輸入檔案名-創建
3,保存檔案-運行-運行到瀏覽器–選擇一個能用的直接測驗
<!DOCTYPE html> <!--是檔案宣告行,用來宣告這是一個HTML檔案 -->
<html> <!-- HTML檔案里的根元素-->
<head> <!-- 網頁中的頭部分,優先于body加載,用來設定網頁的屬性-->
<meta charset="utf-8"> <!-- 設定網頁的編碼 -->
<title>你好,HTML</title> <!-- 設定網頁的標題 -->
</head>
<body><!-- 網頁的體部分,放展示的資料 -->
hell o html~
hello html~ <br></br>
<!-- br標簽是換行
表示一個空格
-->
hello html~
hello html~
hello html~
hello html~
</body>
</html>
三,HTML的常見標簽
–1,概述
1,輸入框: 單選多選
2,圖片
3,按鈕
4,視頻
5,超鏈接
–2,標題,串列,圖片標簽

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>測驗 標題標簽</title>
</head>
<body>
<!-- 3.圖片標簽
src屬性用來指定圖片的位置(先保證圖片資源和網頁在同一級目錄)
width屬性用來指定圖片的寬度,單位是像素px
height屬性用來指定圖片的高度,單位是百分比
-->
<img src="logo.png" width="30px" height="10%"/>
<img src="logo.png" width="30px" height="10%"/>
<!-- 2.串列標簽
有序串列orderlist: ol是定義串列 li定義串列項
無序串列unorderlist: ul是定義串列 li定義串列項
-->
<ul>
<li>31省區市新增本土確診65例</li>
<li>神十三航天員圓滿完成出艙任務</li>
</ul>
<ol>
<li>31省區市新增本土確診65例</li>
<li>神十三航天員圓滿完成出艙任務</li>
</ol>
<!-- 1.標題標簽 h1大~h6小 自動換行 -->
<h1>hello</h1>
<h2>hello</h2>
<h3>hello</h3>
<h4>hello</h4>
<h5>hello</h5>
<h6>hello</h6>
</body>
</html>
–3,超鏈接,輸入框標簽
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>測驗 超鏈接標簽</title>
</head>
<body>
<!-- 2.input輸入框 -->
密碼輸入框:<input type="password" />
普通輸入框:<input type="text" />
數字輸入框:<input type="number" />
日歷輸入框:<input type="date" />
日歷輸入框:<input type="week" />
單選框:<input type="radio" />男
多選框:<input type="checkbox" />迪麗熱巴
普通按鈕: 沒有提交資料的功能,只能點點
<input type="button" value="注冊"/>
<button>登錄</button>
提交按鈕:把用戶在瀏覽器輸入的資料提交給后端的java程式處理
<input type="submit"/>
<button type="submit">提交</button>
<br />
<!-- 1.超鏈接標簽
href屬性表示可以被點擊
target屬性表示用什么方式打開
默認值是_self當前視窗,_blank是在新視窗打開
-->
<a href="http://www.baidu.com/" target="_blank">百度一下</a>
<!-- 錨定:回到固定位置 -->
<a name="top">我是頂部</a>
<h1>如何套取富婆的歡心</h1>
<h1>如何套取富婆的歡心</h1>
<h1>如何套取富婆的歡心</h1>
<h1>如何套取富婆的歡心</h1>
<a href="#top">點我,回去頂部</a><!--通過#獲取name屬性的值-->
</body>
</html>
–4,表格標簽
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>測驗 表格標簽</title>
</head>
<body>
<!-- 1.準備表格
結構:table里包含行tr,tr里包含列td
屬性:border設定邊框,width寬度,bgcolor背景色
cellspacing單元格的距離
colspan是列合并:把多個列合并成一個大列,值是指合并幾個
rowspan是行合并:把多個行合并成一個大行,值是指合并幾個
-->
<table border="1px" width="500px"
cellspacing="0px" bgcolor="greenyellow">
<tr>
<td colspan="2">11</td>
<td>13</td>
</tr>
<tr>
<td>21</td>
<td>22</td>
<td rowspan="2">23</td>
</tr>
<tr>
<td>31</td>
<td>32</td>
</tr>
</table>
</body>
</html>
四,作業
制作兩個表格


轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/353454.html
標籤:其他
上一篇:誰能悄悄告訴我:EDG到底是啥?
下一篇:IDEA插件分享(實用推薦)
