使用JAX-RS覆盖HTTP方法 [英] Overwrite HTTP method with JAX-RS
问题描述
今天的浏览器(或HTML< 5)仅支持HTTP GET和POST,但是为了进行RESTful通信,还需要PUT和DELETE。如果解决方法不应该是使用Ajax,则需要使用隐藏的表单字段来覆盖实际的HTTP方法。
Today's browsers (or HTML < 5) only support HTTP GET and POST, but to communicate RESTful one need PUT and DELETE too. If the workaround should not be to use Ajax, something like a hidden form field is required to overwrite the actual HTTP method.
Rails使用以下技巧:
Rails uses the following trick:
<input name="_method" type="hidden" value="put" />
是否有可能与JAX-RS做类似的事情?
Is there a possibility to do something similar with JAX-RS?
推荐答案
不是严格意义上的JAX-RS解决方案,但是Spring 3.0附带了 HiddenHttpMethodFilter
,它完全实现了rails的技巧,默认为相同的 _method
参数。
Not strictly a JAX-RS solution but spring 3.0 comes with a HiddenHttpMethodFilter
that implements exactly the trick that rails does, defaults to the same _method
parameter.
请注意,您不需要使用所有弹簧来使用这个过滤器,您可以在 web.xml
中配置它,并忽略其余的春天。
Note that you don't need to be using all of spring to use this filter, you can just configure it in your web.xml
and ignore the rest of spring.
这篇关于使用JAX-RS覆盖HTTP方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!