Spring:为什么我不能用@ResponseBody获取POST参数?

时间:2013-10-12 04:02:19

标签: java spring jsp servlets post

我的JSP

<form method="POST" action="/searchClips">
   <input type="text" name="streamer">
   <input type="checkbox" name="player" value="hello">Hello
   <input class="searchButton" type="image" src="/static/images/buttons/button_search.png"
                       alt="Search">
</form>

我的Servlet

@Controller
public class HomeController {
    @RequestMapping(value = {"/searchClips"}, method = RequestMethod.POST, consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE)
    public String searchClips(@RequestBody Clip clip) {
        System.out.println("hi");
        System.out.println(clip);
        return "index";
    }
}

当我点击搜索按钮(对/ searchClip进行POST)时,我收到了415响应代码:

Problem accessing /views/searchClips. Reason:

    Unsupported Media Type

这是我的日志:

DispatcherServlet - DispatcherServlet with name 'dispatcher' processing POST request for [/searchClips]
RequestMappingHandlerMapping - Looking up handler method for path /searchClips
RequestMappingHandlerMapping - Returning handler method [public java.lang.String com.projectName.controllers.HomeController.searchClips(com.projectName.models.Clip)]
DefaultListableBeanFactory - Returning cached instance of singleton bean 'homeController'
ExceptionHandlerExceptionResolver - Resolving exception from handler [public java.lang.String com.projectName.controllers.HomeController.searchClips(com.projectName.models.Clip)]: org.springframework.web.HttpMediaTypeNotSupportedException: Content type 'application/x-www-form-urlencoded' not supported
DispatcherServlet - Null ModelAndView returned to DispatcherServlet with name 'dispatcher': assuming HandlerAdapter completed request handling
DispatcherServlet - Successfully completed request

任何人都知道问题是什么?

enter image description here

0 个答案:

没有答案