【问题标题】:Usage and Implementation of Head, Option, Trace http methods with ServletServlet中Head、Option、Trace http方法的使用与实现
【发布时间】:2015-10-21 09:06:55
【问题描述】:

我想通过使用 Servlet 来实现以下方法来了解它们的工作方式。

doHead()  
doTrace()  
doHead()  
doOption()
doDelete()

每个教程和文档中都给出了语法和理论含义,但我没有找到它们的实际使用和实现。

你能帮我解决我们使用这些方法和实际实现代码的场景吗?

我尝试从 html 表单调用这些函数并实现了相应的方法,但它不起作用。

<form action="trace" method="trace">
<input type="submit">
</form>
<form action="trace" method="option">
<input type="submit">
</form>

【问题讨论】:

  • 请参阅 HTTP 规范以了解一般 HTTP 请求的语义以及具体的每个 HTTP 方法。这些 servlet 方法只是 HTTP 标准的反映。

标签: java forms http servlets web


【解决方案1】:

正如@Tpolnik 所说,您最好先了解这些HTTP 方法的语义。以下是这些方法的简要说明表,摘自RFC 7231 - Section 4.1

+---------+-------------------------------------------------+-------+
| Method  | Description                                     | Sec.  |
+---------+-------------------------------------------------+-------+
| GET     | Transfer a current representation of the target | 4.3.1 |
|         | resource.                                       |       |
| HEAD    | Same as GET, but only transfer the status line  | 4.3.2 |
|         | and header section.                             |       |
| POST    | Perform resource-specific processing on the     | 4.3.3 |
|         | request payload.                                |       |
| PUT     | Replace all current representations of the      | 4.3.4 |
|         | target resource with the request payload.       |       |
| DELETE  | Remove all current representations of the       | 4.3.5 |
|         | target resource.                                |       |
| CONNECT | Establish a tunnel to the server identified by  | 4.3.6 |
|         | the target resource.                            |       |
| OPTIONS | Describe the communication options for the      | 4.3.7 |
|         | target resource.                                |       |
| TRACE   | Perform a message loop-back test along the path | 4.3.8 |
|         | to the target resource.                         |       |
+---------+-------------------------------------------------+-------+

由于大多数现代浏览器不支持使用GETPOST以外的方法提交表单,因此使用TRACEOPTION作为传输用户数据的方法没有意义到 HTTP 服务器。请参阅this W3C document 了解更多信息。

【讨论】:

  • 我也没有在 Wc3 文档上找到任何有用的信息。
  • @ShamsuddinAltamash 大多数浏览器在按照文档建议提交表单时可能仅支持GETPOST。我认为您最好尝试选择另一种方式来发出HEADOPTION 请求,例如AJAX 或Chrome 扩展程序Postman 等其他http 客户端。
猜你喜欢
  • 1970-01-01
  • 2021-12-24
  • 2020-08-08
  • 2019-07-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多