【问题标题】:org.springframework.web.servlet.PageNotFound - Request method 'POST' not supported http status 405org.springframework.web.servlet.PageNotFound - 请求方法'POST'不支持http状态405
【发布时间】:2016-11-11 04:31:04
【问题描述】:

我正在向控制器发帖,这是带有动作参数值的表单

<div class="form-group">    
                          <form action="searchT">
                              <label class=" control-label col-sm-2">No</label>
                              <div class="col-sm-4"> <input class="form-control" type='text' name='searchName' id='searchName'/> </div>
                              <div class="col-sm-4"><input class="btn btn-success" type='submit' value='Validate'/></div>
                          </form>
                         </div>

这是在单击按钮时从数据库中获取值的控制器代码

@RequestMapping("searchT")
    public ModelAndView searchTOE(@RequestParam("searchName") String searchName) {  
        logger.info("Searching the T: "+searchName);
        List<TOE> tinList = TOEService.getAllTins(searchName);
        return new ModelAndView("serviceDescription", "tList", tList);      
    }

当我点击提交时出现此错误

org.springframework.web.servlet.PageNotFound - 请求方法'POST'不是 支持

HTTP Status 405 - Request method 'POST' not supported

type Status report

message Request method 'POST' not supported

description The specified HTTP method is not allowed for the requested resource

.

【问题讨论】:

  • 据我所知,默认请求方法是 GET,因此您必须在控制器中指定请求类型
  • 那为什么告诉请求方法post不支持
  • 不应该是请求方式GET不支持吗?
  • 如果这是问题
  • 尝试在您的表单中添加 method="GET" ,希望这会奏效。 &lt;form action="searchT" method="GET"&gt;

标签: spring spring-mvc http-post http-status-code-405


【解决方案1】:

@RequestMapping("searchT")

默认方法类型是GET。您应该在RequestMapping 中提及方法类型为POST

【讨论】:

    猜你喜欢
    • 2013-03-03
    • 2015-06-26
    • 1970-01-01
    • 2012-06-24
    • 2015-05-01
    • 2015-04-09
    • 2016-03-29
    • 2014-09-24
    • 1970-01-01
    相关资源
    最近更新 更多