我正在使用表单,当我点击“提交”时,它会点击以下 Controller 。
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
@Controller
public class ViewController
{
private final static String USERNAME = "username";
private final static String PASSWORD = "password";
@RequestMapping(value = "/", method = RequestMethod.GET)
public String authenticate()
{
return "authenticate.html";
}
@RequestMapping(value = "/connector", method = RequestMethod.POST)
public String connector(final HttpServletRequest request)
{
final HttpSession session = request.getSession();
final String username = request.getParameter(USERNAME);
final String password = request.getParameter(PASSWORD);
session.setAttribute(USERNAME, username);
session.setAttribute(PASSWORD, password);
return "connectors.html";
}
}
我知道该方法正在被命中,因为我在其中放置了断点。但是,我仍然收到上述错误。
编辑:我已经发布了整个 Controller 而不仅仅是方法。
Edit2:我的html表单如下:
<form action="/connector" method="post" name="authentication_form">
<input type="text" name="username" id="username">
<input type="password" name="password" id="password">
<a href = "javascript:document.authentication_form.submit();" class="link-next">
Next
<i class="ico-chevron-right"></i>
</a>
</form>
我错过了什么?非常感谢任何帮助。
最佳答案
您是否尝试使用 @RestController 注释而不是 @Controller ?
关于java - SpringBoot 说 "Request method ' POST' 不支持,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34274235/