I use Spring Web MVC and Hibernate to develop my application.
My login.jsp page has the following code:
<form:form method="post" commandName="User">
User Name :
<form:input path="email"/>
Password :
<form:input path="password"/>
<input type="submit" align="center" value="Execute">
Now my servlet.xml file has the following code:
<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>
My UserValidateFormController has the following code:
public class UserValidateFormController extends SimpleFormController {
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("login", model);
}
protected Object formBackingObject(HttpServletRequest request) throws ServletException {
User user = new User();
return user;
}
public void setUserSecurityProcessor(IUserSecurityProcessor userSecurityProcessor) {
this.userSecurityProcessor = userSecurityProcessor;
}
In my UserValidateFormController, while sending a send event, I check if the username and password are correct or not.
It works fine, and if both match, then redirecting to layout.jsp is fine too.
But if the username or password is incorrect, I want to redirect to the same login.jsp page and display the corresponding error.
Please offer me a solution on what to do to redirect to the same controller.
Thanks in advance.