【发布时间】:2010-12-11 04:43:26
【问题描述】:
我正在使用 Spring Web MVC 和 Hibernate 来开发我的应用程序。
我的 login.jsp 页面有以下代码:
<form:form method="post" commandName="User">
User Name :
<form:input path="email"/>
Password :
<form:input path="password"/>
<input type="submit" align="center" value="Execute">
现在,我的 servlet.xml 文件有以下代码:
<bean name="/uservalidate.htm" class="com.sufalam.mailserver.presentation.web.UserValidateFormController">
<property name="sessionForm" value="true"/>
<property name="commandName" value="User"/>
<property name="commandClass" value="com.sufalam.mailserver.bean.User"/>
<property name="formView" value="login"/>
<property name="successView" value="layout.jsp"/>
<property name="userSecurityProcessor" ref="IUserSecurityProcessor"/>
</bean>
我的 UserValidateFormController 有以下代码:
public class UserValidateFormController extends SimpleFormController {
/** Logger for this class and subclasses */
protected final Log logger = LogFactory.getLog(getClass());
private IUserSecurityProcessor userSecurityProcessor;
public ModelAndView onSubmit(Object command)
throws ServletException, SufalamException {
ModelAndView mav = new ModelAndView();
Map model = new HashMap();
String username = ((User) command).getEmail();
String password = ((User) command).getPassword();
List userChecking = new ArrayList();
userChecking = userSecurityProcessor.findByAll(username, password, 0.0);
System.out.println("userChecking length = "+userChecking.size());
if (userChecking.size() == 1) {
return new ModelAndView("layout");
//return new ModelAndView(new RedirectView(getSuccessView()));
}
return new ModelAndView("login", model);
}
protected Object formBackingObject(HttpServletRequest request) throws ServletException {
User user = new User();
return user;
}
public void setUserSecurityProcessor(IUserSecurityProcessor userSecurityProcessor) {
this.userSecurityProcessor = userSecurityProcessor;
}
在处理提交事件时,在我的 UserValidateFormController 中,我正在检查用户名和密码是否正确..
它工作正常,如果两者都匹配,那么它会重定向到 layout.jsp,这也很好。
但是如果用户名或密码不正确,那么我想重定向到相同的 login.jsp 页面并显示相应的错误..
请建议我重定向到同一个视图控制器的解决方案..
提前谢谢..
【问题讨论】:
-
...如果您不介意询问,如果您在使用 Spring 时遇到了麻烦,是否有特殊原因为什么您要推出自己的安全措施而不是实施 Acegi(或现在称为 Sprint 安全性)?
-
是的,我使用过 ACEGI 并且非常了解它......但是,我目前的系统不需要那么多负载......这个问题只是基本的 spring 概念,如何我重定向到同一个名为 JSP 页面的控制器..
-
@vector:Spring Security 有点像怪物,对于简单的任务来说,它往往比它的价值更麻烦
-
每次有人使用
SimpleFormController,小宝贝耶稣都会哭…… -
你解决了吗?如果是,请发布解决方案...
标签: java jakarta-ee spring-mvc