SpringBoot说:“请求方法‘POST’不支持

问题描述:

我使用的一种形式,当我点击提交它击中以下控制器。SpringBoot说:“请求方法‘POST’不支持

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"; 
} 
} 

我知道方法被击中,因为我已经把断点它可是,我还是得到上述错误

编辑:我已经发布了整个控制器,而不仅仅是方法
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> 

我错过了什么?任何帮助是极大的赞赏。

+0

发布完整的控制器类 – Reimeus

+0

我已经编辑我的职务,以显示完整的类@Reimeus – MaxPower

+0

请添加你的您是否正在使用,春季安全或任何类型的安全使用 – reos

您是否尝试使用@RestController批注而不是@Controller?

+0

我做了,它只返回一个字符串,它说“connectors.html” – MaxPower

+0

既然你要求返回该字符串,我不明白是什么问题。 – Eria

+0

我希望它返回我的实际html页面 – MaxPower

我不得不创建另一种使用GET并重定向到它的方法。

@RequestMapping(value = "/connector", method = RequestMethod.POST) 
public String connector(final HttpServletRequest request, final AuthenticationCredentials authenticationCredentials) 
{ 
    final HttpSession session = request.getSession(); 
    session.setAttribute("Authentication", authenticationCredentials); 

    return "redirect:/test"; 
} 

@RequestMapping(value="/test", method = RequestMethod.GET) 
public String connector() 
{ 
    return "steve.html"; 
}