2014-01-21 37 views
0

我收到以下警告: 不支持請求方法'POST'。不支持Spring MVC-Request方法'POST':org.springframework.web.servlet.PageNotFound handleHttpRequestMethodNotSupported

控制器方法:

@Controller 
public class UserServiceController { 

@RequestMapping(value = "/login", method = RequestMethod.POST) 
@Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class) 
public String login(@RequestParam Map<String,String> requestParams) throws Exception{ 
    System.out.println(requestParams.values()); 
    loginService.userAuthentication(requestParams.get("loginuname"), requestParams.get("loginpassword")); 

    System.out.println("Before return"); 
    return "static/profile.html"; 
} 
} 

分配器一servlet.xml中

<mvc:resources mapping="/static/**" location="/WEB-INF/static/" /> 

的index.html

<script language="javascript" type="text/javascript"> 
function submitForm(){ 
    document.login.submit(); 
} 
</script> 
<div id="login" class="login"> 
<form action="http://localhost:8080/SampleApp/login" name="login" method="post"> 
     <input type="text" value = "Email" name="loginuname" id="loginuname" class="loginbasetxt"> 

     <input type="text" value="Password" name="loginpassword" id="loginpassword" class="loginbasetxt"> 
     <img src="static/img/tb-login-button.png" onclick="submitForm()"/> 
</form> 
</div> 

然而,如果我會改變方法= RequestMethod.GET和相應地在登錄頁面,然後它會工作。

請注意,問題是在返回「static/profile.html」;

FYI profile.html的位置是WEB-INF /靜態/

謝謝!

+0

獲取的警告在哪裏呢?你是否將'login'中的登錄信息作爲請求參數提交或作爲表單提交? – chrylis

+0

你確定你的表單的URL是否正確,action屬性是action =「POST」? – isah

+0

請發佈http表單,發送的請求以及控制器類的類關鍵字旁邊的註釋。 – Ralph

回答

3

當您向POST表單發送到HTTP服務器時,表單的內容不會作爲查詢參數發送;相反,表單(通常)作爲application/x-www-form-urlencoded類型的實體上傳。您的方法中不使用@RequestParam,而是定義一個具有與表單域對應的字段的Java類,並使用@ModelAttribute FormClass form

0

你應該試試這個:

return "forward:/static/profile.html"; 
+0

使用redirect/static/profile.html解決了問題 – Touchstone