2015-12-14 158 views
0

我使用的一種形式,當我點擊提交它擊中以下控制器。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

回答

1

您是否嘗試使用@RestController批註而不是@Controller?

+0

我做了,它只返回一個字符串,它說「connectors.html」 – MaxPower

+0

既然你要求返回該字符串,我不明白是什麼問題。 – Eria

+0

我希望它返回我的實際html頁面 – MaxPower

0

我不得不創建另一種使用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"; 
} 
相關問題