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
POST 在Request-URI所标识的资源后附加新的数据
HEAD 请求获取由Request-URI所标识的资源的响应消息报头
PUT 请求服务器存储一个资源,并用Request-URI作为其标识
DELETE 请求服务器删除Request-URI所标识的资源
TRACE 请求服务器回送收到的请求信息,主要用于测试或诊断
CONNECT 保留将来使用
OPTIONS 请求查询服务器的性能,或者查询与资源相关的选项和需求
2.Http测试示例代码:
- import java.io.BufferedReader;
- import java.io.IOException;
- import java.io.InputStreamReader;
- import java.io.OutputStreamWriter;
- import java.io.PrintWriter;
- import java.net.Socket;
- import java.net.UnknownHostException;
- public class Test {
- public static void main(String[] args) {
- Socket s = null;
- PrintWriter pw = null;
- BufferedReader br = null;
- try {
- s = new Socket("211.98.132.67",8080);
- pw = new PrintWriter(new OutputStreamWriter(s.getOutputStream()));
- pw.println("GET / HTTP/1.1"); //此处可选择get或者post
- pw.println("HOST:localhost");
- pw.println("Content-Type:text/html"); //指明访问资源类型
- pw.println(); //空行 代表请求结束
- pw.flush();
- br = new BufferedReader(new InputStreamReader(s.getInputStream()));
- String str = null;
- while ((str = br.readLine()) != null) {
- System.out.println(str);
- }
- } catch (UnknownHostException e) {
- e.printStackTrace();
- } catch (IOException e) {
- e.printStackTrace();
- }finally {
- try {
- if (br != null) {
- br.close();
- br = null;
- }
- if (pw != null) {
- pw.close();
- pw = null;
- }
- if (s != null) {
- s.close();
- s = null;
- }
- } catch (IOException e) {
- System.out.println("IO异常。。。");
- e.printStackTrace();
- }
- }
- }
- }
3.Web Application的概念
(1)Web Application NameWEB-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"/>