“status“:405,“error“ Request method ‘POST‘ not supported“
Error Messages:
-“status”:405,“error”:“Method Not Allowed”,“exception”:“org.springframework.web.HttpRequestMethodNotSupportedException”,“message”:“Request method ‘POST’ not supported”
code:
@Controller
public class EmpController {
@Autowired
private EmpService empService;
@GetMapping("/empadd")
public String empAdd(Model model) {
model.addAttribute("list",empService.showAll());
return "emp-add";
}
@PostMapping("/add")
public String add(Emp emp, MultipartFile file){
empService.insert(emp,file);
return "emp-add";
}
}
Reason:
As it says in the Spring REST guide,
@RequestMapping maps all HTTP operations by default
but if, as they suggest, you added a specification of the allowable http methods:
@RequestMapping(method=GET)
then only GETs will be allowed. POSTs will be disallowed.
If you want to allow both GET and POST, but disallow all other http methods, then annotate your controller method thusly:
@RequestMapping(value = "/greeting", method = {RequestMethod.GET, RequestMethod.POST})
public Greeting greeting(@RequestParam(value="name", defaultValue="World") String name) {
return new Greeting(counter.incrementAndGet(),
String.format(template, name));
}
When you start the application, all the request handler mappings are logged out. You should see a line like this in your log (in the IDE console or command line window):
s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/greeting],methods=[GET || POST]}" onto public hello.Greeting hello.GreetingController.greeting(java.lang.String)
Solution:
Modify
@GetMapping("/empadd")
to
@RequestMapping("/empadd")
Read More:
- Java Web uses AJAX POST Method 405 terror [Solved]
- [Solved] spingboot Error: I/O error on POST request for “9411/api/v2/spans“: connect timed out
- Asynchronous processing of HTTP request by Java_ Method 1: through callable
- Asynchronous processing of HTTP request by Java_ Method 2: through deferredresult
- SpringCloud Use openFeign Multipartfile to Upload Files Error: Current request is not a multipart request
- [Solved] error: method does not override or implement a method from a supertype
- org.hibernate.exception.SQLGrammarException: could not extract ResultSet, Resolve MySQL 5.7.5 or above GROUP_BY is not supported
- How to Solve FATAL ERROR in native method: JDWP on getting class status, jvmtiError=JVMTI_ERROR_WRONG_PHASE
- Using Post no Body Error: socket hang up [How to Solve]
- Abstract method and static method of java interface
- IDEA-Error java error release version 5 not supported (How To Fix)
- Eureka Error: registration status: 204 deregister status: 200
- [Solved] nacos Error: Client not connected,current status:STARTING,StatusRuntimeException
- [Solved] java.io.IOException: Got error, status=ERROR, status message, ack with firstBadLink as
- springboot jsp: There was an unexpected error (type=Not Found, status=404). No message available
- Microservice call exceptions: error feign.RetryableException: Read timed out executing POST http://xxx…….
- JAVA: How to use the third-party font library method (using the third-party TTF / TTC font library method)
- [Solved] The main method caused an error: Could not deploy Yarn job cluster.
- There was an unexpected error (type=Internal Server Error, status=500).Invalid bound statement (not
- [Solved] Java.lang.IllegalStateException: getReader() has already been called for this request