2014-03-30 60 views
0

我有这样一段代码:Spring MVC映射 - 为什么路径正在改变?

@RequestMapping(value="login/authUser", method=RequestMethod.POST) 
public String authUser(@RequestParam("login") String login, 
         @RequestParam("password") String password, ModelMap model) 
(...) 

哪些应该抓住用户的身份验证:

<div id ="loginBar"> 
     <form id="loginForm" action="login/authUser" method="post"> 
      <label>Login:</label> 
      <input id="login" type="text" title="podaj login" name="login"/><br><br> 
      <label>Hasło:</label> 
      <input id ="password" type="password" title="podaj haslo, minimum 8 znaków" name="password"><br> 
      <input id ="loginAuthorisationFailed" type="text"/><br> 
      <input id="loginButton" type="submit" value="Zaloguj"><br> 
     </form> 
    </div> 

如果这是不好的,它应该返回index.jsp和有关坏数据

(...) 
else{ 
      model.put("info", "Bad data!"); 
      return "index"; 

信息转至h1 HTML标签:

<h1>${info}</h1> 

这是路径,然后我看到浏览器:

http://localhost:8084/pracainz/login/authUser 

但后来我尝试再次登录,在浏览器的路径是不同的:

http://localhost:8084/pracainz/login/login/authUser 

和Tomcat显示我的错误:

The requested resource() is not available. 

它增加了额外的“/登录”,我不知道为什么。我能做些什么来阻止以这种方式形成行为,我能做些什么,每次强制路径,,复位”当我尝试发送形式春天

不幸的是,这是行不通的:?

action="${pageContext.servletContext.contextPath}/login/authUser" 

我将非常高兴,如果有人想帮我

预先感谢您

解决:! 解决方案:

我应该使用:

<%@taglib uri="http://www.springframework.org/tags/form" prefix="form"%> 
(...) 

<form:form id="loginForm" action="${pageContext.servletContext.contextPath}/login/authUser" method="post"> 
(...) 
</form:form> 

而是简单的HTML标签

回答

0

使用Spring标签库,更具体地说spring:url创建行动正确的URL。退房this SO问题的详细信息

+0

谢谢,我也发现不同的解决方案;我应该用春天标签代替简单HMTL