最近我们转移到 spring 3.0 Controller 处理如下:
@Controller
public class MyController {
@RequestMapping(method = RequestMethod.POST)
protected String onSubmit ( Form form, Errors errors) {
// handle POST
}
@RequestMapping(method = RequestMethod.GET)
protected void getForm ( Form form ) {
// handle GET
}
}
现在,由于 HEAD 请求,我们的日志中出现了很多异常。
org.springframework.web.HttpRequestMethodNotSupportedException: Request method 'HEAD' not supported
at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter$ServletHandlerMethodResolver.resolveHandlerMethod(AnnotationMethodHandlerAdapter.java:621)
at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.invokeHandlerMethod(AnnotationMethodHandlerAdapter.java:422)
at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.handle(AnnotationMethodHandlerAdapter.java:415)
...
我想像 GET 请求一样支持 HEAD 请求,但当然要遵守 HTTP 引用:
The HEAD method is identical to GET except that the server MUST NOT
return a message-body in the response. The metainformation contained in the HTTP headers in response to a HEAD request SHOULD be identical to the information sent in response to a GET request. This method can be used for obtaining metainformation about the entity implied by the request without transferring the entity-body itself. This method is often used for testing hypertext links for validity, accessibility, and recent modification. http://www.ietf.org/rfc/rfc2616.txt
有没有人有一个优雅的解决方案,或者甚至有开箱即用的 Spring 解决方案?
我在网上搜索,但没有找到任何答案。
最佳答案
我相信这就是您正在寻找的: http://www.axelfontaine.com/2009/09/transparently-supporting-http-head.html
https://stackoverflow.com/questions/3803015/