2014-01-21 32 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