http request method and response codes

HTTP方法与HTTP状态码详解
本文详细介绍了HTTP方法(GET、POST、PATCH、PUT、DELETE)及其示例,同时阐述了HTTP状态码的分类与具体含义,帮助开发者理解HTTP交互的基本流程。

 ============================

HTTP_Method
============================
HTTP MethodActionExamples
GETObtain information about a resourcehttp://example.com/api/orders
(retrieve order list)
GETObtain information about a resourcehttp://example.com/api/orders/123
(retrieve order #123)
POSTCreate a new resourcehttp://example.com/api/orders
(create a new order, from data provided with the request)
PATCHUpdate a resourcePATCH 将来会比 PUT用的更多,PUT为完整代替, PATCH支持partial replace 
PUTReplace a whole resource http://example.com/api/orders/123
(update order #123, from data provided with the request)
DELETEDelete a resourcehttp://example.com/api/orders/123
(delete order #123)

============================
HTTP_CODES
============================
 参见: http://en.wikipedia.org/wiki/List_of_HTTP_status_codes
 1xx Informational
 2xx Success
 3xx Redirection
 4xx Client Error
 5xx Server Error
 具体有:
 100: 'Continue',
 101: 'Switching 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',
 306: '(Unused)',
 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 Timeout',
 409: 'Conflict',
 410: 'Gone',
 411: 'Length Required',
 412: 'Precondition Failed',
 413: 'Request Entity Too Large',
 414: 'Request-URI Too Long',
 415: 'Unsupported Media Type',
 416: 'Requested Range Not Satisfiable',
 417: 'Expectation Failed',
 418: "I'm a teapot",
 428: 'Precondition Required',
 429: 'Too Many Requests',
 431: 'Request Header Fields Too Large',
 500: 'Internal Server Error',
 501: 'Not Implemented',
 502: 'Bad Gateway',
 503: 'Service Unavailable',
 504: 'Gateway Timeout',
 505: 'HTTP Version Not Supported',
 511: 'Network Authentication Required'

To modify the HelloCounter servlet into the VisitorCounter servlet with session tracking, you can make the following changes: 1. Rename the class from HelloCounter to VisitorCounter. 2. In the doGet method, retrieve the session object from the request using request.getSession() method. 3. Within the session object, retrieve the visitor count attribute using session.getAttribute("count"), and if it does not exist, set it to 0 using session.setAttribute("count", 0). 4. Increment the visitor count using session.setAttribute("count", count + 1). 5. Print the visitor count to the response using the PrintWriter object. 6. Close the PrintWriter object. The modified code would look like this: ``` import java.io.*; import javax.servlet.*; import javax.servlet.http.*; public class VisitorCounter extends HttpServlet { public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html; charset=\"UTF-8\""); PrintWriter servletOut = response.getWriter(); HttpSession session = request.getSession(); Integer count = (Integer) session.getAttribute("count"); if (count == null) { count = 0; } count += 1; session.setAttribute("count", count); servletOut.println("<html><head><title>Visitor Counter</title></head><body>"); servletOut.println("<h1>Visitor Count: " + count + "</h1>"); servletOut.println("</body></html>"); servletOut.close(); } } ``` Note: This code assumes that the web.xml file has been correctly configured to map the servlet to a URL.
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值