如果您对Spring,不支持请求方法“POST”和spring不支持使用注解进行配置感兴趣,那么这篇文章一定是您不可错过的。我们将详细讲解Spring,不支持请求方法“POST”的各种细节,并对spr
如果您对Spring,不支持请求方法“ POST”和spring不支持使用注解进行配置感兴趣,那么这篇文章一定是您不可错过的。我们将详细讲解Spring,不支持请求方法“ POST”的各种细节,并对spring不支持使用注解进行配置进行深入的分析,此外还有关于HTTP状态405-不支持请求方法“ POST”(Spring MVC)、HTTP状态405-具有Spring Security的Spring MVC不支持请求方法'POST'、java – Spring Boot – 不支持请求方法’POST’、java – 不支持请求方法’POST’的实用技巧。
本文目录一览:- Spring,不支持请求方法“ POST”(spring不支持使用注解进行配置)
- HTTP状态405-不支持请求方法“ POST”(Spring MVC)
- HTTP状态405-具有Spring Security的Spring MVC不支持请求方法'POST'
- java – Spring Boot – 不支持请求方法’POST’
- java – 不支持请求方法’POST’
Spring,不支持请求方法“ POST”(spring不支持使用注解进行配置)
首先要道歉,问这个重复的问题。
其实在我的Spring应用程序,我有user.jsp
和professional.jsp
这是我的User.jsp:
<form:form action="profile/user" modelAttribute="profile"> <div> <jsp:include page="professional.jsp"></jsp:include> </div></form:form>
这是我的professional.jsp:
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%><%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%><fieldset id="profile_proffiesional"> <form:form action="profile/proffiesional" modelAttribute="PROFESSIONAL" method="POST"> <p> <label for="position">Position</label> <form:input path="position" tabindex="4" /> </p> <p> <label for="location">Location</label> <form:input path="location" tabindex="5" /> </p> <p> <label for="description">Description</label> <form:input path="description" tabindex="5" /> </p> <p> <input type="submit" value="Add"> </p> </form:form></fieldset>
这是我的Controller类:
@Controller@RequestMapping(value = "profile")public class UserProfileController { @Autowired private UserService userService; @Autowired private SessionData sessionData; @RequestMapping(value = "user", method = RequestMethod.GET) public String user(Model model) throws Exception { model.addAttribute("PROFESSIONAL", new UserProfessionalForm()); model.addAttribute("EDUCATIONAL", new UserEducationalForm()); model.addAttribute("AWARDS", new UserAwardsForm()); return "profile/user"; } @RequestMapping(value = "proffessional", method = RequestMethod.POST) public @ResponseBody String forgotPassword(UserProfessionalForm professionalForm, BindingResult result, Model model) { UserProfileVO userProfileVO = new UserProfileVO(); userProfileVO.setUser(sessionData.getUser()); userService.saveUserProfile(userProfileVO); model.addAttribute("professional", professionalForm); return "Your Professional Details Updated"; }}
Problem
是当我们单击中的Add
按钮时professional.jsp
,服务器控制台中没有响应,但显示以下警告消息:
29 Mar, 2013 1:03:51 PM org.springframework.web.servlet.mvc.support.DefaultHandlerExceptionResolver handleHttpRequestMethodNotSupportedWARNING: Request method ''POST'' not supported
为什么会出现此警告?我已经指定method =“ POST” ..
请帮忙..
答案1
小编典典您的user.jsp:
<form:form action="profile/proffesional" modelAttribute="PROFESSIONAL"> --- --- </form:form>
在您的控制器类中:
(使其成为一个有意义的完整方法名称。。听见,我认为您是在DB中插入记录。)
@RequestMapping(value = "proffessional", method = RequestMethod.POST) public @ResponseBody String proffessionalDetails( @ModelAttribute UserProfessionalForm professionalForm, BindingResult result, Model model) { UserProfileVO userProfileVO = new UserProfileVO(); userProfileVO.setUser(sessionData.getUser()); userService.saveUserProfile(userProfileVO); model.addAttribute("PROFESSIONAL", professionalForm); return "Your Professional Details Updated"; }
HTTP状态405-不支持请求方法“ POST”(Spring MVC)
如何解决HTTP状态405-不支持请求方法“ POST”(Spring MVC)?
我发现了导致HTTP错误的问题。
在“ setFalse()
保存”按钮触发的函数中,我的代码试图提交包含该按钮的表单。
function setFalse(){
document.getElementById("hasId").value ="false";
document.deliveryForm.submit();
document.submitForm.submit();
当我删除document.submitForm.submit();
它的作品:
function setFalse(){
document.getElementById("hasId").value ="false";
document.deliveryForm.submit()
@RogerLindsjö感谢您发现我没有传递正确参数的错误!
解决方法
我收到此错误: HTTP Status 405 - Request method ''POST'' not supported
我正在尝试做的是创建一个带有下拉框的表单,该表单会根据在另一个下拉框中选择的其他值进行填充。例如,当我在customerName
框中选择一个名称时,onChange
应运行.jsp页面中的函数,然后提交提交的页面,然后在customerCountry
框中再次加载相应的值。
但是我收到此HTTP状态405错误。我在互联网上搜索了解决方案,但找不到任何有帮助的方法。这是我的代码的相关部分:
jsp页面的一部分
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<style>
.error { color: red; }
</style>
<script>
function repopulate(){
document.deliveryForm.submit();
}
function setFalse(){
document.getElementById("hasId").value ="false";
document.deliveryForm.submit();
// document.submitForm.submit(); (This was causing the error)
}
</script>
</head>
<body>
<h1>Create New Delivery</h1>
<c:url var="saveUrl" value="/test/delivery/add" />
<form:form modelAttribute="deliveryDtoAttribute" method="POST" action="${saveUrl}" name="deliveryForm">
<table>
<tr>
<td><form:hidden id="hasId" path="hasCustomerName" value="true"/></td>
</tr>
<tr>
<td>Customer Name</td>
<td><form:select path="customerName" onChange="repopulate()">
<form:option value="" label="--- Select ---" />
<form:options items="${customerNameList}" />
</form:select>
</td>
<td><form:errors path="customerName" css/></td>
</tr>
<tr>
<td>Customer Country</td>
<td><form:select path="customerCountry">
<form:option value="" label="--- Select ---" />
<form:options items="${customerCountryList}" />
</form:select>
</td>
<td><form:errors path="customerCountry" css/></td>
</tr>
</form:form>
<form:form name="submitForm">
<input type="button" value="Save" onClick="setFalse()"/>
</form:form>
</body>
</html>
控制器的一部分:
@RequestMapping(value = "/add",method = RequestMethod.GET)
public String getDelivery(ModelMap model) {
DeliveryDto deliveryDto = new DeliveryDto();
model.addAttribute("deliveryDtoAttribute",deliveryDto);
model.addAttribute("customerNameList",customerService.listAllCustomerNames());
model.addAttribute("customerCountryList",customerService
.listAllCustomerCountries(deliveryDto.getCustomerName()));
return "new-delivery";
}
// I want to enter this method if hasId=true which means that a value in the CustomerName
// drop down list was selected. This should set the CountryList to the corresponding values
// from the database. I want this post method to be triggered by the onChange in the jsp page
@RequestMapping(value = "/add",method = RequestMethod.POST,params="hasCustomerName=true")
public String postDelivery(
@ModelAttribute("deliveryDtoAttribute") DeliveryDto deliveryDto,BindingResult result,ModelMap model) {
model.addAttribute("deliveryDtoAttribute",deliveryDto);
model.addAttribute("customerNameList",customerService.listAllCustomerNames());
model.addAttribute("customerCountryList",customerService
.listAllCustomerCountries(deliveryDto.getCustomerName()));
return "new-delivery";
}
// This next post method should only be entered if the save button is hit in the jsp page
@RequestMapping(value = "/add",params="hasCustomerName=false")
public String postDelivery2(
@ModelAttribute("deliveryDtoAttribute") @Valid DeliveryDto deliveryDto,ModelMap model) {
if (result.hasErrors()) {
model.addAttribute("deliveryDtoAttribute",customerService
.listAllCustomerCountries(deliveryDto.getCustomerName()));
return "new-delivery";
} else {
Delivery delivery = new Delivery();
//Setters to set delivery values
return "redirect:/mis/home";
}
}
我怎么会得到这个错误?任何帮助将非常感激!谢谢
编辑: 更改hasId
为hasCustomerName
。我仍然收到HTTP Status 405 - Request method
''POST'' not supported
错误。
EDIT2: 注释掉setFalse
导致错误的函数中的行
// D
HTTP状态405-具有Spring Security的Spring MVC不支持请求方法'POST'
如何解决HTTP状态405-具有Spring Security的Spring MVC不支持请求方法''POST''?
我不确定这是否有帮助,但是我遇到了同样的问题。
您正在使用带有CSRF保护的springSecurityFilterChain。这意味着通过POST请求发送表单时必须发送令牌。尝试将下一个输入添加到表单中:
<input type="hidden"
name="${_csrf.parameterName}"
value="${_csrf.token}"/>
解决方法
我使用freemarker模板作为视图部分创建了一个Spring mvc应用程序。在此尝试使用表格添加模型。我也在使用spring security这是代码
员工
<fieldset>
<legend>Add Employee</legend>
<form name="employee" action="addEmployee" method="post">
Firstname: <input type="text" name="name" /> <br/>
Employee Code: <input type="text" name="employeeCode" /> <br/>
<input type="submit" value=" Save " />
</form>
employeeController.java
@RequestMapping(value = "/addEmployee",method = RequestMethod.POST)
public String addEmployee(@ModelAttribute("employee") Employee employee) {
employeeService.add(employee);
return "employee";
}
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<!-- Spring MVC -->
<servlet>
<servlet-name>appServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>appServlet</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/spring/appServlet/servlet-context.xml,/WEB-INF/spring/springsecurity-servlet.xml
</param-value>
</context-param>
<!-- Spring Security -->
<filter>
<filter-name>springSecurityFilterChain</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>
<filter-mapping>
<filter-name>springSecurityFilterChain</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
</web-app>
Spring-security.xml
<beans:beans xmlns="http://www.springframework.org/schema/security"
xmlns:beans="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/security
http://www.springframework.org/schema/security/spring-security-3.2.xsd">
<http security="none" pattern="/resources/**"/>
<!-- enable use-expressions -->
<http auto-config="true" use-expressions="true">
<intercept-url pattern="/login" access="isAnonymous()"/>
<intercept-url pattern="/**" access="hasRole(''ROLE_ADMIN'')" />
<!-- access denied page -->
<access-denied-handler error-page="/403" />
<form-login
login-page="/login"
default-target-url="/"
authentication-failure-url="/login?error"
username-parameter="username"
password-parameter="password" />
<logout logout-success-url="/login?logout" />
<!-- enable csrf protection -->
<csrf />
</http>
<authentication-manager>
<authentication-provider user-service-ref="userDetailsService" >
<password-encoder hash="bcrypt" />
</authentication-provider>
</authentication-manager>
</beans:beans>
单击提交按钮时,将返回错误`
HTTP状态405-不支持请求方法“ POST”
`我在ftl和controller上都给出了POST方法。那为什么会这样呢?
java – Spring Boot – 不支持请求方法’POST’
这是我的控制器:
@RestController public class LoginController { UserWrapper userWrapper = new UserWrapper(); @RequestMapping(value = "/api/login",method = RequestMethod.POST,headers = "Content-type: application/*") public @ResponseBody ResponseEntity getCredentials(@RequestBody UserDTO userDTO) { User user = userWrapper.wrapUser(userDTO); if (userDTO.getpassword().equals(user.getpassword())) { return new ResponseEntity(HttpStatus.OK); } else { return new ResponseEntity(HttpStatus.BAD_REQUEST); } } }
我在localhost发送邮件请求:8080 / api / login但它不起作用.你有什么想法吗?
编辑:
UserDTO:
public class UserDTO implements Serializable { private String email; private String password; //getters and setters
和json我发送:
{ "email":"email@email.com","password":"password" }
解决方法
@Configuration class SecurityConfig extends WebSecurityConfigurerAdapter { @Override protected void configure(HttpSecurity http) throws Exception { http.csrf().disable(); } }
java – 不支持请求方法’POST’
While HTTP defines these four methods,HTML only supports two: GET and POST. Fortunately,there are two possible workarounds: you can either use JavaScript to do your PUT or DELETE,or simply do a POST with the ‘real’ method as an additional parameter (modeled as a hidden input field in an HTML form).
他们已经完成了后者,并且可以使用以下spring MVC表单标签来实现:
<form:form method="delete"> <input type="submit" value="Delete"/> </form:form>
问题是,当我单击“删除”时,我的页面会抛出以下错误:
HTTP Status 405 - Request method 'POST' not supported
我将org.springframework.web的调试级别更改为debug并找到以下消息:
DEBUG AnnotationMethodHandlerExceptionResolver - Resolving exception from handler [foo.bar.MessageForm@da9246]: org.springframework.web.HttpRequestMethodNotSupportedException: Request method 'POST' not supported
我使用RestClient和DELETE方法,并按预期调用该方法.我在这做错了什么?
解决方法
细节可以找到here:
关于Spring,不支持请求方法“ POST”和spring不支持使用注解进行配置的问题就给大家分享到这里,感谢你花时间阅读本站内容,更多关于HTTP状态405-不支持请求方法“ POST”(Spring MVC)、HTTP状态405-具有Spring Security的Spring MVC不支持请求方法'POST'、java – Spring Boot – 不支持请求方法’POST’、java – 不支持请求方法’POST’等相关知识的信息别忘了在本站进行查找喔。
本文标签: