【问题标题】:How are POST parameters handled in Spring 3 when some are in URL?当一些在 URL 中时,如何在 Spring 3 中处理 POST 参数?
【发布时间】:2011-09-19 11:38:01
【问题描述】:

我通常检索如下 POST 参数:

@RequestMapping(method = RequestMethod.POST)
public ModelAndView create(
    @RequestParam(value = "first_name", required = false) String firstName,
    HttpServletRequest request
) {

但是如果某些参数在 URL 中,例如http://example.com/post/path?last_name=Smith?当RequestMapping 为 POST 时,Spring 是否应该从 URL 和 POST 数据中获取所有参数?

基本上,Facebook 通过 POST 发送 signed_request 参数,同时通过 URL 参数发送 request_ids 等其他参数。我需要两者兼得。

【问题讨论】:

    标签: spring jakarta-ee spring-mvc java-ee-6 java-ee-5


    【解决方案1】:

    但是如果 URL 中有一些参数,比如 http://example.com/post/path?last_name=Smith?春天应该 从 URL 和 POST 数据中获取所有参数 RequestMapping 是 POST 吗?

    是的,spring 将获取 POST 请求的所有参数值(在表单和 url 中)。但在你的情况下

     @RequestParam(value = "first_name", required = false) String firstName, 
    

    将为空。因为在你的url中,参数名称是last_name。 :D

    【讨论】:

    • 嗯...我的问题的重点是 Spring 是否从 POST 和 URL 中获取了参数。 first_name 在 POST 中,last_name 在 URL 中。
    • YES,spring 会从 Form:input 和 url 中获取参数。
    【解决方案2】:

    我不确定这是否有用地回答了你的问题,但是,说到 Linux:

    1. POST 参数出现在服务器的标准输入上;

    2. GET 参数(URL 中的参数)出现在 QUERY_STRING 中。

    HTH

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-04-20
      • 1970-01-01
      • 2021-12-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多