首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
社区首页 >问答首页 >Spring:不支持请求方法'POST‘

Spring:不支持请求方法'POST‘
EN

Stack Overflow用户
提问于 2014-11-28 13:10:31
回答 1查看 2.6K关注 0票数 1

浏览论坛,但没有找到解决办法,可以解决我的问题。有2页: index.jsp --起始页,包括要填充的表单和结果列表;edit.jsp允许从index.jsp提供的结果列表中编辑任意行的数据。当我填写所有成功提交的数据时,当我尝试编辑结果列表中的任何行时,我重定向到edit.jsp,但是如果我提交了更改,就会抛出一个异常:HTTPSTAT405-RequestMethod 'POST‘不支持。我想知道如何处理这个问题。

index.jsp

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<%@taglib prefix="s" uri="http://www.springframework.org/tags" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>

<html>
  <head>
    <title></title>
  </head>
  <body>
    <form:form method="post" action="add" modelAttribute="account">
        <table>
        <tr>
            <td><form:label path="number">Number</form:label></td>
            <td><form:input path="number"/></td>
        </tr>
        <tr>
            <td><form:label path="amount">Amount</form:label></td>
            <td><form:input path="amount"/></td>
        </tr>
        <tr>
            <td><form:label path="currency">Currency</form:label></td>
            <td><form:input path="currency"/></td>
        </tr>
        <tr>
            <td><form:label path="date">Date</form:label></td>
            <td><form:input path="date" type="date"/>
        </tr>
        </table>
        <input type="submit" value="Submit"/>
    </form:form>
    <table>
        <tr border="1">
            <td>Number</td>
            <td>Amount</td>
            <td>Currency</td>
            <td>Date</td>
        </tr>
        <c:forEach items="${listOfAccounts}" var="items">
        <tr border="1">
            <td>${items.number}</td>
            <td>${items.amount}</td>
            <td>${items.currency}</td>
            <td>${items.date}</td>
            <td><a href="<c:url value='edit/${items.id}'/>">edit</a></td>
        </tr>
        </c:forEach>
  </body>
</html>

edit.jsp

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>

<html>
<head>
    <title>Edit Account</title>
</head>
<body>
    <form:form modelAttribute="account" method="post" action="edited">
        <form:hidden path="id" value="${account.id}"></form:hidden>
        <form:label path="number">Number</form:label>
        <form:input path="number" value="${account.number}"/><br>
        <form:label path="amount">Amount</form:label>
        <form:input path="amount" value="${account.amount}"/><br>
        <form:label path="currency">Currency</form:label>
        <form:input path="currency" value="${account.currency}"/><br>
        <form:label path="date">Date</form:label>
        <form:input path="date" type="date" value="${account.date}"/>
        <input type="submit" value="Submit"/>
    </form:form>
</body>
</html>

Controller.java

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
@Controller
public class AccountController {

    @Autowired
    private AccountService accountService;
    private Account account;

    @RequestMapping(value="/", method = RequestMethod.GET)
    public String welcomeMethod(ModelMap map) {
        Account account = new Account();
        map.addAttribute("account", account);
        map.addAttribute("listOfAccounts", accountService.getListOfAccounts());
        return "index";
    }

    @RequestMapping(value="add", method = RequestMethod.POST)
    public String addAccount(@ModelAttribute(value="account") Account account, ModelMap map) {
        accountService.addAccount(account);
        map.addAttribute("listOfAccounts", accountService.getListOfAccounts());
        return "index";
    }

    @RequestMapping(value="edit/{id}", method = RequestMethod.GET)
    public String editAccount(@PathVariable("id") int id, ModelMap model) {
        Account account = accountService.getAccountById(id);
        model.addAttribute("account", account);
        return "edit";
    }

    @RequestMapping(value="edited", method = RequestMethod.POST)
    public String updateAccount(@ModelAttribute(value="account") Account account, ModelMap map) {
        accountService.updateAccount(account);
        map.addAttribute("listOfAccounts", accountService.getListOfAccounts());
        return "index";
    }
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-11-28 22:39:15

您的问题是在表单中使用相对映射,当您单击“编辑”时,您的URL变成/edit/{someid},而您的edit.jsp表单被加载。当您编辑数据并单击submit时,您的URL将变成/edit/{someid}/edited,映射将匹配使用GET方法的/edit/{someid}处理程序方法,这就是您获得错误的原因。

要解决这个问题,在edit.jsp简单中向操作添加反斜杠,action="/edited"

希望它能帮上忙

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/27195925

复制
相关文章
c++发送post请求_request的post方法作用
RestSharp是一个轻量的,不依赖任何第三方的模拟Http的组件或者类库。RestSharp具体以下特性;支持net4.0++,支持HTTP的GET, POST, PUT, HEAD, OPTIONS, DELETE等操作,支持oAuth 1, oAuth 2, Basic, NTLM and Parameter-based Authenticators等授权验证等。截止当前目前是github最高stars的http类库。
全栈程序员站长
2022/10/03
1.9K0
c++发送post请求_request的post方法作用
【OkHttp】OkHttp Get 和 Post 请求 ( 同步 Get 请求 | 异步 Get 请求 | 同步 Post 请求 | 异步 Post 请求 )
【OkHttp】OkHttp 简介 ( OkHttp 框架特性 | Http 版本简介 ) 【OkHttp】Android 项目导入 OkHttp ( 配置依赖 | 配置 networkSecurityConfig | 配置 ViewBinding | 代码示例 ) 【OkHttp】OkHttp Get 和 Post 请求 ( 同步 Get 请求 | 异步 Get 请求 | 同步 Post 请求 | 异步 Post 请求 )
韩曙亮
2023/03/29
16.6K0
解决nginx代理转发post请求变get请求方法
post请求经过nginx转发变get请求原因 nginx的机制是所有转发默认是get,所以会导致post请求经过nginx转发后会被转化为get请求。 get—–>get post—–>get
超级小可爱
2023/02/20
7.2K0
GET请求和POST请求
在网络编程中,HTTP协议是最常用的协议之一,用于在客户端和服务器之间传输数据。HTTP协议中最常用的两种请求方式是GET和POST请求。这篇博客将介绍GET和POST请求的区别,以及在不同场景中如何选择使用这两种请求方式。
chao超的搬运文章
2023/10/15
5650
原生js发送post请求_javascript发送post请求
说明: 要测试restsharp的功能,首先需要了解http传参和下载上传文件的原理,请参考: c#:从http请求报文看http协议中参数传递的几种方式 c#使用Http上传下载文件
全栈程序员站长
2022/10/04
8.6K0
原生js发送post请求_javascript发送post请求
ab发送cookie和post请求的方法
ab是apache自带的压力测试工具,近期需要压测一个接口,涉及使用post请求,并在其中带cookie。方法总结如下:
跑马溜溜的球
2020/12/07
3.5K0
urlconnection post请求
package com.rayootech.activiti.util; import java.io.BufferedReader; import java.io.InputStreamReader; import java.net.HttpURLConnection; import java.net.URL; public class Test { public static void main(String[] args) { String loadJSON =
挑战者
2018/11/09
2.1K0
python post请求
post请求只需构建一个Request对象,并把参数传递给Request对象的data属性即可(也可以在urlopen方法中传递给data参数)。
灯珑LoGin
2022/10/31
1.8K0
post请求包含哪些参数(请求方式post和get)
1)、HTTP 协议是以 ASCII 码 传输,建立在 TCP/IP 协议之上的应用层规范。规范把 HTTP 请求分为三个部分:状态行、请求头、消息主体。 2)、协议规定 POST 提交的数据必须放在消息主体(entity-body)中,但协议并没有规定数据必须 使用什么编码方式 。实际上,开发者完全可以自己决定消息主体的格式,只要最后发送的 HTTP 请求满足上面的格式就可以。 3)、数据发送出去,还要服务端解析成功才有意义。一般服务端语言如 php、python 等,以及它们的 framework,都内置了自动解析常见数据格式的功能。服务端通常是根据请求头(headers)中的 Content-Type 字段来获知请求中的消息主体是用何种方式编码,再对主体进行解析。
全栈程序员站长
2022/07/29
3.8K0
resttemplate post请求发送body_java发送post请求
1POST传递参数 :采用 LinkedMultiValueMap ,不能使用HashMap
全栈程序员站长
2022/10/03
2.5K0
http请求中get和post方法的区别
一般我们在浏览器输入一个网址访问网站都是GET请求;再FORM表单中,可以通过设置Method指定提交方式为GET或者POST提交方式,默认为GET提交方式。
用户7880705
2020/11/06
4.5K0
POST方法提交请求时,List类型映射失败
执行过程中数据映射失败,经过测试,MergeRequestVo映射没问题,MergeRequestFileListVo映射失败。
似水的流年
2019/12/05
1.1K0
HttpClient-Get请求、Post请求
有参数,请求链接为url(http://localhost:8083/getdemo2)
wangmcn
2022/07/25
2.7K0
HttpClient-Get请求、Post请求
iOS同步post请求
-(NSDictionary * )SynchronousRequestUserBaseFromRemoteWith:(NSString *)userId{
星宇大前端
2019/01/15
1.8K0
python 异步post请求
import aiohttp headers = {'User-Agent': 'Dalvik/2.1.0 (Linux; U; Android 6.0.1; Nexus 5 Build/MMB29K) tuhuAndroid 5.24.6', 'content-type': 'application/json'} async with aiohttp.ClientSession(headers=headers) as sess:
Wyc
2021/08/13
3.5K0
curl发送POST请求
curl发送POST请求 今天写Gitlab的一个merge request hook,使用curl来简化测试请求.简单备忘一下,如何使用curl发送POST请求.以下为使用curl发送一个携带json数据的POST请求.
技术小黑屋
2018/09/04
6.9K0
WebView进行post请求
大多数情况下我们一般用WebView去加载一个界面就行了,但是有时候你想要进行post请求,比如你抓取到提交参数,想模拟一些pc端浏览器的请求,比如12306火车票.那要怎么做呢? 抓取的参数如下:
夏洛克的猫
2018/10/18
3.2K0
WebView进行post请求
AJAX发送POST请求
AJAX(Asynchronous JavaScript and XML)是一种用于在 Web 应用程序中进行异步数据交换的技术。在 AJAX 请求中,我们可以使用 POST 方法发送数据到服务器,以便进行处理和保存。
堕落飞鸟
2023/05/18
4.1K0
python处理get请求和post请求
#处理get请求,不传data,则为get请求 import urllib from urllib.request import urlopen from urllib.parse import u
用户1220053
2018/03/29
3.4K0
点击加载更多

相似问题

请求方法'POST‘不支持Spring

11

不支持Spring请求方法'POST‘

11

Spring不支持请求方法'POST‘

21

Spring :不支持请求方法'POST‘

30

不支持Spring请求方法'POST‘

30
添加站长 进交流群

领取专属 10元无门槛券

AI混元助手 在线答疑

扫码加入开发者社群
关注 腾讯云开发者公众号

洞察 腾讯核心技术

剖析业界实践案例

扫码关注腾讯云开发者公众号
领券
社区富文本编辑器全新改版!诚邀体验~
全新交互,全新视觉,新增快捷键、悬浮工具栏、高亮块等功能并同时优化现有功能,全面提升创作效率和体验
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档
查看详情【社区公告】 技术创作特训营有奖征文