3

我的 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>

我的小服务程序

@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";
    }
}

当我单击搜索按钮时,它会向 /searchClips 发送 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

有谁知道问题是什么?

在此处输入图像描述

4

0 回答 0