"Request method 'POST' not supported" in Spring boot

Help me, please. I can’t fix this error:

'debug' enabled in Spring boot There was an unexpected error <Request method 'POST' not supported>

Thanks for your help

This my Controller

package com.example.Login1;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

@Controller
public class Login_controller {
	@Autowired
	Login_Service service;

	@RequestMapping("/")
	public String fromlogin() {
		return "login";
	}
	@RequestMapping("/new")
	public String new_User(Model model) {
		User user = new User();
		model.addAttribute("user", user);
		return "create";
	}

	@RequestMapping(value = "/save" , method = RequestMethod.POST)
	public String save_User(@ModelAttribute("user") User user) {
		service.save(user);
		return "redirect:/";
	}
}

And this my HTML

<div class="container">
    <form  action="#" th:action="@{/save}" th:object="${user}" method="post">
   
        <label >FullName</label>
        <input type="text" id="name" name="name" placeholder="Fullname..." th:field="*{name}"/>
        
        <label >Password</label>
        <input type="text" id="password" name="Password" placeholder="Password..." th:field="*{password}"/>
 
        <label >Email</label>
        <input type="text" id="email" name="email" placeholder="email..." th:field="*{email}"/>
 
        <label >PhoneNumber</label>
        <input type="text" id="phone" name="phone" placeholder="PhoneNumber..." th:field="*{phone)}"/>
 
        <label >Address</label>
        <input type="text" id="address" name="address" placeholder="Address..." th:field="*{address}"/>
 
        <button type="submit" value="Submit">Submit</button>
    </form>
</div>
</body>
</html>

This my error

A post was merged into an existing topic: Topic lưu trữ các post off-topic - version 3

Diễn đàn không cấm tiếng Anh nha các bạn :kissing_heart:

3 posts were merged into an existing topic: Topic lưu trữ các post off-topic - version 3

lí do như trên

You are having a grammar error, aren’t you?

Why the subject in this sentences isn’t capitalized?

Now, let’s get straight to the point. In the controller’s code, you didn’t support a POST request to “/” so the error occurred. If you want to fix this error, you just simply put this code method = RequestMethod.POST to @RequestMapping("/")

2 Likes

I fixed this. I repaired this to a table, this accept. you can explain for me. thanks you

Haizzz… What is “this”? Your answer had mistake again. Whatever.

1 Like

Sorry. actually I’m not good at english

But. The most important is that correcting errors is not my English

What the heck are there grammar error? Even a 7th grade student would not has these. I think you should relearn about the basic knowledge of English. Now! :face_with_symbols_over_mouth:

thanks you reminded I’am studing and improving my english …
I’fixed this exist thanks for your help

Again? my English skills not my English. Whatever. If you aren’t having anything to ask now, you should close this topic. Goodbye.

1 Like
83% thành viên diễn đàn không hỏi bài tập, còn bạn thì sao?