• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
返回主页

donfaquir

  • 博客园
  • 首页
  • 新随笔
  • 联系
  • 订阅
  • 管理

springMVC怎么改变form的提交方式为put或者delete

想着练习一下创建restful风格的网站呢,结果发现在jsp页面上并不能灵活使用put和delete提交方式.下面我的解决办法

一. form 只支持post和get两种提交方式,只支持get提交方式##

二. 使用过滤器+form隐藏标签的方式在后台改变form提交方式

a)在web.xml文件中添加过滤器###

	<filter>
		<filter-name>HiddenHttpMethodFilter</filter-name>
		<filter-class>org.springframework.web.filter.HiddenHttpMethodFilter</filter-class>
	</filter>
	
	<filter-mapping>
		<filter-name>HiddenHttpMethodFilter</filter-name>
		<url-pattern>/*</url-pattern>
	</filter-mapping>

注意:web.xml文件的标签有严格的前后顺序,标签的位置不能放错,不然会提示

The content of element type "web-app" must match "(icon?,display-
 name?,description?,distributable?,context-param*,filter*,filter-mapping*,listener*,servlet*,servlet-
 mapping*,session-config?,mime-mapping*,welcome-file-list?,error-page*,taglib*,resource-env-
 ref*,resource-ref*,security-constraint*,login-config?,security-role*,env-entry*,ejb-ref*,ejb-local-ref*)".

b)在jsp页面的form中增加隐藏节点###

<input type="hidden" name="_method" value="put" />

value的值可以为"delete,put,get"等http允许的提交方式名

语雀
posted @ 2018-08-15 18:59  donfaquir  阅读(1347)  评论(0)    收藏  举报
刷新页面返回顶部

公告

博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3