spring HiddenHttpMethodFilter使用问题

spring可以将表单的post的方法“转化”为put或者是delete方法,就是利用spring中的HiddenHttpMethodFilter过滤器来实现的,但是今天在使用spring4进行项目的过程中,在进行如上操作的时候,报出了如下错误:

HTTP Status 405 - JSPs only permit GET POST or HEAD
type Status report
message JSPs only permit GET POST or HEAD
description The specified HTTP method is not allowed for the requested resource.
Apache Tomcat/8.0.21

更为奇怪的是,requestMapping里边的方法还进行了输出,只是没有跳转到指定的jsp页面,百思不得其解,上网查找发现是,tomcat8的版本问题,在tomcat8版本以前,可以正常执行,醉了。

以下是stackoverflow上面的说明:

Since JSP 2.3 (Tomcat 8) only supported method for JSP is GET POST or HEAD:

https://jcp.org/aboutJava/communityprocess/maintenance/jsr245/245-MR3.html http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/jasper/servlet/JspServlet.java?view=diff&r1=1497877&r2=1497878&pathrev=1497878

But, I suppose, it is a big incompatible change as, for example, for exception handler it is used to forward to JSP for rendering exception and iso JSP view since JSP 2.3 response is:

Method Not Allowed
HTTP Status 405 - JSPs only permit GET POST or HEAD 

description The specified HTTP method is not allowed for the requested resource.
Apache Tomcat/8.0.3

If we use REST and Spring HandlerExceptionResolver in case of exception we bump into this problem for sure. Are there any workaround for this problem (iso change http method type)?

暂时想到的解决方案:
1、降低tomcat版本,降到7,什么都不会有了。
2、设置重定向,这个里边默认的是不允许使用jsp页面,那么我们可以重定向到一个controller或者是requestMapping也是可以的。在return的时候不要直接写jsp的位置,而是写一个requestMapping的位置。


后记
以后碰到类似的感觉不是自己的问题,不要一遍一遍的看代码(浪费了好多时间),一定要从网上找答案,一定要从网上找答案,一定要从网上找答案!!!重要且每次都记不住的事情要说三遍

  • 7
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 8
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 8
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值