尚学堂马士兵servlet/JSP笔记(一、Http协议及WebApp初步)

本文介绍了HTTP常见状态码及其含义,包括成功、重定向、客户端错误等,并提供了一个简单的HTTP测试示例代码。此外,还解释了Web应用程序的基本结构。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

目录(?)[+]

1.http常见状态:

"100" : Continue                                  "101" : witching Protocols           
"200" : OK                                             "201" : Created           
"202" : Accepted                                  "203" : Non-Authoritative Information           
"204" : No Content                              "205" : Reset Content           
"206" : Partial Content                        "300" : Multiple Choices           
"301" : Moved Permanently               "302" : Found           
"303" : See Other                                 "304" : Not Modified           
"305" : Use Proxy                                 "307" : Temporary Redirect           
"400" : Bad Request                           "401" : Unauthorized           
"402" : Payment Required                 "403" : Forbidden           
"404" : Not Found                                "405" : Method Not Allowed           
"406" : Not Acceptable                       "407" : Proxy Authentication Required           
"408" : Request Time-out                 "409" : Conflict 
"410" : Gone                                        "411" : Length Required           
"412" : Precondition Failed              "413" : Request Entity Too Large           
"414" : Request-URI Too Large      "415" : Unsupported Media Type           
"416" : Requested range not satisfiable           "417" : Expectation Failed           
"500" : Internal Server Error              "501" : Not Implemented           
"502" : Bad Gateway                           "503" : Service Unavailable           

"504" : Gateway Time-out                   "505" : HTTP Version not supported


GET     请求获取Request-URI所标识的资源
POST    在Request-URI所标识的资源后附加新的数据
HEAD    请求获取由Request-URI所标识的资源的响应消息报头
PUT     请求服务器存储一个资源,并用Request-URI作为其标识
DELETE  请求服务器删除Request-URI所标识的资源
TRACE   请求服务器回送收到的请求信息,主要用于测试或诊断
CONNECT 保留将来使用
OPTIONS 请求查询服务器的性能,或者查询与资源相关的选项和需求 

2.Http测试示例代码:

[java]  view plain copy
  1. import java.io.BufferedReader;  
  2. import java.io.IOException;  
  3. import java.io.InputStreamReader;  
  4. import java.io.OutputStreamWriter;  
  5. import java.io.PrintWriter;  
  6. import java.net.Socket;  
  7. import java.net.UnknownHostException;  
  8.   
  9.   
  10. public class Test {  
  11.   
  12.     public static void main(String[] args) {  
  13.         Socket s = null;  
  14.         PrintWriter pw = null;  
  15.         BufferedReader br = null;  
  16.           
  17.         try {  
  18.             s = new Socket("211.98.132.67",8080);  
  19.             pw = new PrintWriter(new OutputStreamWriter(s.getOutputStream()));  
  20.             pw.println("GET / HTTP/1.1");   //此处可选择get或者post  
  21.             pw.println("HOST:localhost");  
  22.             pw.println("Content-Type:text/html");   //指明访问资源类型  
  23.             pw.println();  //空行 代表请求结束  
  24.             pw.flush();  
  25.               
  26.             br = new BufferedReader(new InputStreamReader(s.getInputStream()));  
  27.             String str = null;  
  28.             while ((str = br.readLine()) != null) {  
  29.                 System.out.println(str);  
  30.             }  
  31.               
  32.         } catch (UnknownHostException e) {  
  33.             e.printStackTrace();  
  34.         } catch (IOException e) {  
  35.             e.printStackTrace();  
  36.         }finally {  
  37.             try {  
  38.                 if (br != null) {  
  39.                     br.close();  
  40.                     br = null;  
  41.                 }  
  42.                 if (pw != null) {  
  43.                     pw.close();  
  44.                     pw = null;  
  45.                 }  
  46.                 if (s != null) {  
  47.                     s.close();  
  48.                     s = null;  
  49.                 }  
  50.             } catch (IOException e) {  
  51.                 System.out.println("IO异常。。。");  
  52.                 e.printStackTrace();  
  53.             }              
  54.         }  
  55.     }  
  56.   
  57. }  



3.Web Application的概念

(1)Web Application Name
    WEB-INF 静态文件直接放在这,就可访问
        web.xml 
            该web app的配置文件
        lib 
            该web app用到的库文件
        classes
            存放编译好的servlet
    META-INF
        存放该web app的上下文信息,符合J2EE标准
(2)Web Application可以直接放在webapp下面
(3)也可以通过配置文件指定到其他目录 <host>里面
    <Context path=“/虚拟路径名“ docBase=”目录位置" debug="0" reloadable="true"/>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值