这是我面临的错误的屏幕截图。
问题是忘记了-密码再次附加在URL中。(请参阅附加图像的地址栏)

我的Controller如下所示:
@Controller
@RequestMapping(value="/forgot-password")
public class ControllerForgotPassword {
@RequestMapping(value = "/email", method = RequestMethod.POST)
public ModelAndView sendMail(HttpServletRequest request) {
String email = (String) request.getParameter("email");
boolean flag=serviceForgotPassword.checkEmail(email);
ModelAndView modelAndView = new ModelAndView();
if(flag)
{
modelAndView.addObject("message", "Mail has been sent to your mail box");
modelAndView.setViewName("forgot-password-sucess");
return modelAndView;
}
else
{
modelAndView.addObject("message", "Please Enter Valid email address");
modelAndView.setViewName("forgot-password");
return modelAndView;
}
}
}forgot-password.jsp内容如下:
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ page contentType="text/html;charset=UTF-8" %>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<%@ taglib prefix="fmt"
uri="http://java.sun.com/jsp/jstl/fmt" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Forgot-Password</title>
</head>
<body>
<p style="color:red;">${message}</p>
<form action="forgot-password/email" method="POST">
<input type="text" name="email"/>
<input type="submit" value="Send Mail">
</form>
</body>
</html>我曾尝试在modelAndView.setViewName("redirect:/forgot-password-sucess");方法中使用sendMail,但随后无法接收来自控制器的消息。
编辑:
如果我添加了作为context/project名称的<form action="/CabFMS/forgot-password/email" method="POST">,那么它没有问题。
是否需要在from操作中随处添加上下文名称以及控制器映射?
我不能在表单动作中只使用forgot-password/email吗?
请帮帮忙。
致以敬意,
阿伦
发布于 2012-10-31 13:52:36
此表单操作必须是绝对的,才能与控制器匹配。它目前正在指定一个相对路径。
<form action="/forgot-password/email" method="POST">
|
add this leading slash编辑:,只有当应用程序位于根上下文时才能工作。
如果将应用程序部署到不同的上下文中,则还需要将上下文添加到表单的action属性中。
一种更好的方法是保留相对路径,并在页面上使用<base>标记,这应该包括上下文--参见 html tag?。我倾向于在JSP中使用以下内容编写Spring应用程序。
<base href="${pageContext.request.scheme}://${pageContext.request.serverName}:${pageContext.request.serverPort}${pageContext.request.contextPath}/">这样,页面中的相对路径就可以自然地根据正确的上下文进行解析,无论在哪里。
https://stackoverflow.com/questions/13158816
复制相似问题