[在此处输入文章标题]
1 web
交给tomcat服务器运行!!!!
今天的目标: http协议
2 Http协议入门
| GET /day09/hello HTTP/1.1 Host: localhost:8080 |
| 请求(浏览器-》服务器) GET /day09/hello HTTP/1.1 Host: localhost:8080 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:35.0) Gecko/20100101 Firefox/35.0 Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 Accept-Language: zh-cn,en-us;q=0.8,zh;q=0.5,en;q=0.3 Accept-Encoding: gzip, deflate Connection: keep-alive |
| 响应(服务器-》浏览器) HTTP/1.1 200 OK Server: Apache-Coyote/1.1 Content-Length: 24 Date: Fri, 30 Jan 2015 01:54:57 GMT this is hello servlet!!! |
3 Http请求
| User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:35.0) Gecko/20100101 Firefox/35.0 Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 Accept-Language: zh-cn,en-us;q=0.8,zh;q=0.5,en;q=0.3 Accept-Encoding: gzip, deflate Connection: keep-alive |
1)GET方式提交
| GET /day09/testMethod.html?name=eric&password=123456 HTTP/1.1 Host: localhost:8080 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:35.0) Gecko/20100101 Firefox/35.0 Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 Accept-Language: zh-cn,en-us;q=0.8,zh;q=0.5,en;q=0.3 Accept-Encoding: gzip, deflate Referer: http://localhost:8080/day09/testMethod.html Connection: keep-alive |
)POST方式提交
| POST /day09/testMethod.html HTTP/1.1 Host: localhost:8080 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:35.0) Gecko/20100101 Firefox/35.0 Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 Accept-Language: zh-cn,en-us;q=0.8,zh;q=0.5,en;q=0.3 Accept-Encoding: gzip, deflate Referer: http://localhost:8080/day09/testMethod.html Connection: keep-alive name=eric&password=123456 |
| HttpSevlet类的源码: protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { if (method.equals(METHOD_GET)) { long lastModified = getLastModified(req); if (lastModified == -1) { else { long ifModifiedSince; try { HEADER_IFMODSINCE); catch (IllegalArgumentException iae) { if (ifModifiedSince < (lastModified / 1000 * 1000)) { else { SC_NOT_MODIFIED); else if (method.equals(METHOD_HEAD)) { long lastModified = getLastModified(req); else if (method.equals(METHOD_POST)) { else if (method.equals(METHOD_PUT)) { else if (method.equals(METHOD_DELETE)) { else if (method.equals(METHOD_OPTIONS)) { else if (method.equals(METHOD_TRACE)) { else { lStrings.getString("http.method_not_implemented"); new Object[1]; format(errMsg, errArgs); SC_NOT_IMPLEMENTED, errMsg); |
4 Http响应
| Content-Length: 24 Date: Fri, 30 Jan 2015 01:54:57 GMT |
| Content-Disposition: attachment; filename=aaa.zip --表示告诉浏览器以下载方式打开资源(下载文件时用到) Transfer-Encoding: chunked Cache-Control: no-cache Pragma: no-cache |