【问题标题】:WARN : org.springframework.web.servlet.PageNotFound - Request method 'GET' not supported警告:org.springframework.web.servlet.PageNotFound - 不支持请求方法“GET”
【发布时间】:2013-03-19 06:31:44
【问题描述】:

启动服务器时出现此异常: HTTP Status 405 - Request method 'GET' not supported

我的控制器是:

@Controller
public class HomeController {

    private static final Logger logger = LoggerFactory.getLogger(HomeController.class);

    @RequestMapping(value = "/", method = RequestMethod.POST)
    public String home(Locale locale, Model model) {
        logger.info("Welcome home! The client locale is {}.", locale);

        return "login";
    }

}

我真的不知道是什么问题,因为我对spring很陌生,甚至无法弄清楚问题是什么。

有人可以指导我解决这个问题

【问题讨论】:

  • 您是否检查过login 中的字符串faces-navigation.xml 是否正确指向您要导航的页面?
  • 这个文件在 faces-navigation.xml 的什么位置??
  • faces-navigation.xml 是 JSF 的东西。没有 JSF 标签,只有 spring-mvc。
  • 我正在使用 spring,不知道为什么会出现这种令人困惑的评论
  • 我可以知道投反对票的原因吗?

标签: java spring spring-mvc spring-security


【解决方案1】:

RequestMapping 错误。

@RequestMapping(值 = "/", 方法 = RequestMethod.POST)

它将只接受 POST 请求并返回 405 StatusCode 任何不是 POST 的请求。

所以,应该是

@RequestMapping(值 = "/", 方法 = RequestMethod.GET)

【讨论】:

  • 降低 spring mvc 的日志级别以进行调试或跟踪,让我们知道结果。
【解决方案2】:

试试这个

改变

@RequestMapping(value = "/", method = RequestMethod.POST)

@RequestMapping(value = "/login", method = RequestMethod.GET)

(在您之前的帖子中,我注意到您有 login-page=login)

【讨论】:

  • 试过这个也没用,之后我添加了spring security,只有我遇到这个问题
  • 发布你的 web.xml 和 spring 上下文 xml
【解决方案3】:

改变

@RequestMapping(value = "/", method = RequestMethod.POST)

@RequestMapping(value = "/login", method = RequestMethod.GET)

【讨论】:

    猜你喜欢
    • 2019-07-31
    • 2013-04-12
    • 1970-01-01
    • 2017-01-18
    • 2014-02-11
    • 2016-11-11
    • 1970-01-01
    • 1970-01-01
    • 2020-08-14
    相关资源
    最近更新 更多