http - Spring 3.0 HEAD 请求

最近我们转移到 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/

相关文章:

java - Spring:如何从 POST 正文中获取参数?

java - 如何将 Class 值设置为 spring bean 属性?

java - 在 Spring 5 Webflux 中启用 CORS?

java - 为什么不推荐使用 HibernateTemplate?

java - Spring Servlet 项目的 web.xml 中加载 contextConfi

java - Java Spring中的重载 Controller 方法

java - Spring实际上是如何引导的?

java - 如何在 Hibernate 中用 TableGenerator 替换已弃用的 Mult

java - hibernate 唯一 key 验证

java - Mybatis Spring多数据库Java配置