SpringMVC 的 POST 提交表单出现 405

【异常】SpringMVC常见405状态码报错,Request method ‘GET‘ not supported / Request method ‘POST‘ is not supported 一般来说,如果你知道接口的访问类型被限制为POST,那么你通常会使用POST方式进行访问。但是,有时候即使你使用了POST方式进行访问,仍然会出现这个异常。这种情况通常是由于将请求接口限制为POST方式,但使用GET方式进行访问所导致的。如果你想发送POST请求,请确保在请求中使用POST方式,而不是GET方式。有些接口可能只支持GET请求,但你却误以为支持POST请求。在这种情况下,你需要确保重定向没有改变请求类型。如果使用了重定向,可能会导致请求类型被篡改。在这种情况下,你需要更正接口的访问类型。 阅读详情

现象

利用 SpringMVC 后端框架,在页面利用表单 (method="post") 提交数据,结果页面报 405 错误,提示 "Request method 'POST' not supported"。


前提

若以下前提和你的项目不匹配,那解决方案可能不适用于你的项目中哦!

  • 全部前端页面采用 html 文件
  • Spring 4.3.13 版本(低于请更新。啰嗦一句,团队更新框架不仅置入新功能,而且会修复旧版本的bug,Spring框架的mvn仓库网址)
  • Controller 类用到 @Controller 和 @RequestMapping 注解

实验

  • 为了方便理解,ViewResolver的后缀先设为空:


  • /resource/html/文件夹内容:

  • Controller 类代码:


  • first.html 页面的表单代码


步骤重现

  1. 往地址栏中输入 http://……(省略)/myProfile/setting,在表单处输入数据。
  2. 数据会被发送至 registerUser 方法并处理。

(数据被成功传输至后台,证明 System.out.println(user); 之前并无出错)

    3. 无法跳转至 first.html,并报 405 错误。

分析

由于使用的是 html 文件,它并不支持响应头带有 post 的应答包,所以会报错。


解决方案

  1. 若条件允许,使用 jsp 等能够接收 post 应答包的页面文件。(快捷,但不建议,jsp 会增加前后端耦合)
  2. 使用 “redirect:映射路径”进行跳转:

以上两种方案皆可完成跳转,并正常运行。

安装和使用pandoc 支持 Markdown、DOCX、LaTeX、HTML、PDF、EPUB 等 60+ 种格式 的互相转换 阅读详情

相关推荐

如何区分Info与CoWoS封装?

这篇文章主要从Info、CoWoS封装的定义、Interposer的种类以及Info、CoWoS封装的种类三方面进行了介绍,希望读者能够有所收获

wangyubo1的博客 7939

405 method not allowed

用Postman测一个接口的时候,返回了405,百度搜,都说把post请求改成get就可以了,但是,代码是这样的 。(公司前辈写的,我只是按要求改了中间的一个小细节) @GetMapping("getPlayHistoryInfo") public String getLivePlayHistoryInfo( @RequestParam("usertoken") String us...

YAOYU007的博客 3829

ML307A模组通过MQTT协议接入OneNET平台的AT指令全解析

本文详细解析了ML307A模组通过MQTT协议接入OneNET平台的完整AT指令流程。从平台侧的产品创建、设备添加,到核心难点连接密钥的计算方法,再到模组侧的基础网络附着、MQTT连接配置、数据收发及调试排错,提供了手把手的实战指南,帮助开发者快速实现物联网设备上云。

weixin_29240711的博客 494

springboot+security报错405方法不支持解决方法

这篇博客主要介绍了在使用 Spring Boot 和 Spring Security 进行 Web 开发过程中,遇到 HTTP 错误码为 405 的错误的解决方法。文章首先列举了可能导致 HTTP 错误码为 405 的几种情况,包括请求方法错误、URL 地址错误、客户端请求参数错误以及 CSRF 防护。然后,详细介绍了在使用 Spring Security 时未禁用 CSRF 防护机制导致的 405 错误,并提供了解决方案。具体来说,我们需要在客户端请求中携带 CSRF Token,步骤包括在 HTML 表

nut_bear的博客 3396

从零到一:Ollama工具在RK3588上的深度优化实践

本文详细介绍了如何在RK3588开发板上深度优化Ollama工具,以高效运行DeepSeek模型。通过CPU与NPU负载平衡、模型量化、温度控制等策略,显著提升性能并降低功耗,适用于边缘计算场景。文章提供了具体的配置命令和优化方案,帮助开发者充分发挥RK3588的硬件潜力。

rgv23456789的博客 312

用生成式AI自动生成测试用例的完整教程

本文旨在帮助测试工程师、开发人员快速掌握“生成式AI自动生成测试用例”的核心技术,覆盖从概念理解、工具选择到实战落地的全流程。无论是Web应用、API接口还是移动端功能测试,你都能找到可复用的方法。本文将按照“概念→原理→实战→避坑”的逻辑展开:先通过生活案例理解生成式AI如何生成测试用例,再拆解核心算法原理,接着用Python代码演示完整生成流程,最后分享实际应用中的优化技巧和未来趋势。生成式AI:能“创造内容”的AI模型(如ChatGPT、CodeLlama),像会写作文的智能笔。测试用例。

AIGC应用创新大全的博客 1581

spring中报错405怎么解决?

翻车现场:首先解释一下出现这个原因是因为:您所用请求方法 和你实际上的请求方法不匹配,我这里出现这个问题的原因就是,controller里面执行删除操作的方法使用的是@DeleteMapping,然而前端使用的是post请求中使用的是,具体如下图:前端:解决方法:就是使用ajax请求,把type换成delete,具体操作如下:

weixin_61189391的博客 816

【Matlab】matlab代码实现sph溃坝模拟

本文介绍了一个基于MATLAB的SPH溃坝模拟实现。代码使用平滑粒子流体动力学方法,通过建立1000个随机分布的粒子,计算粒子间的相互作用力来模拟流体运动。模拟过程包括初始化参数、粒子创建、密度压力更新、速度位置计算以及可视化展示。核心算法采用poly6Kernel和spikyKernelGradient函数处理粒子间作用力。该示例为二维简化模型,仅包含基本物理参数和计算流程,实际应用需进一步优化扩展。

unber的博客 208

Python 技术篇-requests发送post请求传文件给flask服务端报405、400问题解决方法

这是我 flask 服务端的一块代码,可以看到有个 methods=['GET', 'POST'],如果没有这个参数,发送请求就会报 405,因为默认能只接收到 get 请求,接收不到 post 请求。 下面链接是我用 requests 发送 post 传文件请求 flask 服务完整实现过程,有兴趣的可以看一下: Python 技术篇-用 flask 库实现 mac 本地文件上传至 windows 服务器指定文件夹下实例演示。 报 400 的原因很大情况下是 requests 参数传的有问题。

小蓝枣的博客 4101

Linux V3H 平台开发系列讲解(串行解串篇)2.2.2 MAX9296 MAX96705 GMSL1 续篇--串行器提前配置

本文详细介绍了在Linux v3h平台上,针对Max9296解串器和解串器max96705的详解配置,验证可出图,内容包括串行器解串器介绍、链路框架、硬件连接、速率配置,以及遇到的图像异常问题及解决方法。

xian18809311584的博客 539

华为OD机试双机位C卷:流量波峰 (C/C++/Py/Java/Js/Go)

华为OD机试双机位C卷 流量波峰,提供C语言、Java、C++、Python、Go、JavaScript源码实现,并提供完整思路讲解。华为OD机试 - 流量波峰。

qq_45776114的博客 2446

基于 SpringMVC 的 POST 提交表单出现 405 错误的解决方法之一

现象利用 SpringMVC 后端框架,在页面利用表单 (method="post") 提交数据,结果页面报 405 错误,提示 "Request method 'POST' not supported"。前提若以下前提和你的项目不匹配,那解决方案可能不适用于你的项目中哦!全部前端页面采用 html 文件Spring 4.3.13 版本(低于请更新。啰嗦一句,团队更新框架不仅置入新功能,而且会修复...

picc_lu的博客 1万+

手把手教你双目测距理论及生成视差图,深度图,点云图像

Stereo Vision, 也叫双目立体视觉,它的研究可以帮助我们更好的理解人类的双眼是如何进行深度感知的。双目视觉在许多领域得到了应用,例如城市三维重建、3D模型构建(如kinect fusion)、视角合成、3D跟踪、机器人导航(自动驾驶)、人类运动捕捉(Microsoft Kinect)等等。双目测距也属于双目立体视觉的一个应用领域,双目测距的基本原理主要是三角测量原理,即通过视差来判定物体的远近。

qq_53545309的博客 2280

springmvc中前台页面form表单提交方法为post,但是报HTTP Status 405 - Request method 'GET' not supported

今天被一个小bug给难住了,虽然最后解决了,但是很影响心情。所以记录一下,警醒自己 在springmvc中前台JSP页面用form方法提交到后台方法中,form的method设置为post,但是总是提示HTTP Status 405 - Request method 'get' not supported 在网上找了一下方法会之后都不得要领,最后在form的action里边的方法后加“/”最后解

dan_0926的博客 2万+

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

pscad IEEE标准系统搭建说明

pscad IEEE标准系统搭建说明,包含典型的IEEE 9节点、14节点、30节点、39节点和118节点系统。内含标准测试系统的原始数据和潮流结果。

Spring MVC 表单提交 405

Spring MVC post表单提交后返回页面报错:405  原因是:post提交,转get方式访问地址报错 解决方式:返回值改为 return "redirect:xxx"

cuiweiqing1988的专栏 319

ssm框架搭建

这个是一个在idea上成功跑起来的ssm框架项目,保存在这里方便以后使用直接下载

附加:一般情况下,通过浏览器的地址栏输入url,发送的只能是get请求;(即【哪些情况下会发送get请求】,【哪些情况下会发送post请求】)

说明: (1)写本文的目的是:在【SpringMVC入门与数据绑定3:Spring MVC数据绑定一:URL Mapping(URL映射);】遇到了post请求报405错误的情况,一时有点迷糊,所以有了本篇博客; (2)本篇博客转载自【GetMapping 和 PostMapping】,【Stack Overflow:@PUT Jersey Error 405: Method not allowed】; 1.哪些情况下会发送get请求,哪些情况下会发送post请求; (本篇博客的重点) (1).

小枯林的博客 3978

LinePhone3.2.7(android端最新版本) sip客户端

SIP客户端For android:LinePhone3.2.7(最新版本),官网地址:http://www.linphone.org/

SpringMVC method属性与http请求方法一致

在springMVC中,@requestMapping注解有method属性,在没有指定method的值时,默认映射所有http请求方法,如果仅想接收一种请求方法,需用method=RequestMethod.GET或其他 请求方法指定,如果提交表单时form标签中method的...

WGH100817的博客 219

HTTP Status 405 - Request method 'GET' not supported

练习SpringMVC时,页面显示405错误,最后查到源头是POST与GET请求的问题。下面给出解决方案,并回顾下HTTP请求的内容 一、运行流程 流程:默认加载index.jsp-&gt;重定向到controller中toLogin方法-&gt;toLogin方法return “login” 找到登陆页-&gt;login.jsp 表单post提交登录信息-&gt;control...

jerryzhou的博客 1万+

Spring MVC Request method 'POST' not supported错误和解决方法

 Spring MVC Request method 'POST' not supported错误, HTTP Status 405 - Request method 'POST' not supported 看了很多原因再仔细看自己的代码,发现是一个很小的问题, 我的提交表单login.jsp &lt;body&gt; &lt;form action="&lt;%=ba...

mrlongdeng的博客 1万+

表单提交报错405的解决方式

大家好,我是雄雄,欢迎关注公众号:雄雄的小课堂。今天,分享一个bug的解决的方法,到最后解决了也不知道为啥这样是可以的,原来的方法是不可以的……01问题描述项目中有这样的一个需求,就是在原...

穆雄雄的博客 2657

关于Idea中SpringMVC表单提交POST提交请求不到数据

org.springframework.web.servlet.PageNotFound handleHttpRequestMethodNotSupported 警告: Request method 'POST' not supported 假如报以上错误,然而通过GET请求方式可以获得数据,可能原因是你提交的post请求的表单中没有声明提交方式 加上这个就可以顺利的拿到后台数据...

Justin 3196

ssm提交post_Spring MVC 表单提交方式为post,后台却进入了get方法

在jsp页面的表单里我明明已经指明了表单提交的方式为POST:为甚么后台却告诉我是GET方法?[WARN]??2013-12-1716:39:53,510method:org.springframework.web.servlet.mvc.support.DefaultHandlerExceptionResolver.handleHttpRequestMethodNotSupported(...

weixin_42498981的博客 714

springMvc的post提交405错误-----只能使用重定向的方式

文章目录前端文件后端控制器类配置类要跳转的success.html页面运行页面:结果: 前端文件 <form action="welcome1" method="post"> <input type="submit" value="post-请求转发"> </form> <br> <br> <form action="welcome2" method="post"> <input

weixin_42988712的博客 996

关于SpringMVC中 HTTP 405

HiddenHttpMethodFilter:浏览器 form 表单只支持 GET 与 POST 请求,而DELETE、PUT 等 method 并不支 持,Spring3.0添加了一个过滤器,可以将这些请求转换 为标准的 http 方法,使得支持 GET、POST、PUT 与 DELETE 请求。 由于浏览器本身只支持get和post方法,因此需要使用_method这个隐藏字段来告知Sprin

Cao66906的博客 1476

Ajax post HTML 405,Ajax POST导致405(方法不允许) – Spring MVC

我正在尝试用POST方法对我的Spring控制器/动作进行ajax调用,并使用@ResponseBody从服务器返回一个对象.奇怪的情况是它在添加spring安全层后停止工作,之前一切正常.我将尝试解释我解决问题的步骤,然后向您展示代码/捕获/等.1.经过一些研究后,我发现了一些答案,说明问题可能与csrf机制有关,所以我禁用它并仍然存在问题. (spring-security.xml bello...

weixin_39624094的博客 847

springmvc:405 request method post not supported

$.ajax({ type: "POST", url: "../userKvtableAll/bindOpt", data: "id="+id, dataType:'JSON', //不加dataType 可能 405 Method Not Allowed这里返回的类型有:json,html,xml,text success: function(msg){ jQuery('#grid-table').trigger("reloadGrid");

我的博客 961
上一篇: html页面间传值(url的形式进行传递)
下一篇: bootstrap自动补全插件
Pancras_gc
博客等级 码龄10年 2粉丝 37原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值