Hi all,
I am new to spring. I am facing a problem with the simpleformcontroller I am having a problem to build a simple login form. the code is as follows.
app-servlet.xml
================================================== =================
<!-- Form Controller for the Login page -->
<bean id="loginValidator" class="com.con.app.businessobjects.LoginValidator"/>
<bean id="LoginController" class="com.con.app.controller.LoginController">
<property name="formView"><value>index.jsp</value></property>
<property name="successView"><value>RacesGeneralList.do</value></property>
<property name="sessionForm"><value>true</value></property>
<property name="commandName"><value>Login</value></property>
<property name="commandClass"><value>com.con.app.beans.Login </value></property>
<property name="validator"><ref bean="loginValidator"/></property>
<property name="loginFacade">
<ref bean="LoginIbatis"/>
</property>
</bean>
<!-- Login Mappings -->
<bean id="LoginIbatis"
class="com.con.app.persistence.sqlmapdao.LoginSqlM apDAO">
<property name="ibatisWrapper">
<ref bean="sqlMapClientTemplate" />
</property>
</bean>
<bean id="sqlMapClientTemplate"
class="org.springframework.orm.ibatis.SqlMapClient Template">
<property name="sqlMapClient">
<ref bean="sqlMapClient" />
</property>
</bean>
<bean id="sqlMapClient"
class="org.springframework.orm.ibatis.SqlMapClient FactoryBean">
<property name="configLocation">
<value>WEB-INF/sql-map-config.xml</value>
</property>
<property name="dataSource">
<ref bean="dataSource" />
</property>
</bean>
<bean id="dataSource"
class="org.springframework.jdbc.datasource.DriverM anagerDataSource">
<property name="driverClassName" value="com.mysql.jdbc.Driver" />
<property name="url" value="jdbc:mysql://localhost:3306/f1" />
<property name="username" value="root" />
<property name="password" value="Passmein" />
</bean>
-----------------------------------------------------------------------------
web.xml
-----------------------------------------------------------------------------
<web-app>
<context-param>
<param-name>log4jConfigLocation</param-name>
<param-value>/WEB-INF/log4j.properties</param-value>
</context-param>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/f1App-servlet.xml</param-value>
</context-param>
<!--Context Load Listener.-->
<listener>
<listener-class>org.springframework.web.context.ContextLoade rListener</listener-class>
</listener>
<listener>
<listener-class>org.springframework.web.util.Log4jConfigList ener</listener-class>
</listener>
<servlet>
<servlet-name>f1App</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherSe rvlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>f1App</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<taglib>
<taglib-uri>/spring</taglib-uri>
<taglib-location>/WEB-INF/lib/spring.tld</taglib-location>
</taglib>
<taglib>
<taglib-uri>/ctag</taglib-uri>
<taglib-location>/WEB-INF/lib/c.tld</taglib-location>
</taglib>
<!-- optional elements include -->
</web-app>
-----------------------------------------------------------------------------
LoginController
-----------------------------------------------------------------------------
package com.cons.app.controller;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.SimpleFormCont roller;
import org.springframework.web.servlet.view.RedirectView;
import com.cons.app.beans.Login;
import com.cons.app.iface.ILogin;
import org.apache.log4j.Logger;
public class LoginController extends SimpleFormController
{
Logger log=Logger.getLogger(LoginController.class);
/**
* instance of the Request Controller.
*/
private ILogin loginFacade;
private HttpSession session;
public LoginController()
{}
/**
* handles the Request.
*
*/
public ModelAndView onSubmit(Object command)
{
logger.debug("onSubmit Begin.........");
Login login=(Login)command;
System.out.println("<<<<<<<<<<<>>>>>>>>>>>>>>>>>>> >>"+login.getUsername());
System.out.println("<<<<<<<<<<<>>>>>>>>>>>>>>>>>>> >>"+login.getPasswd());
System.out.println("<<<<<<<<<<<>>>>>>>>>>>>>>>>>>> >>"+login.getRole());
if(null!=login.getUsername() && null!=login.getPasswd())
{
session.invalidate();
return new ModelAndView(new RedirectView(getSuccessView()));
}
logger.debug("onSubmit end");
return new ModelAndView(new RedirectView(getFormView()));
}
public ILogin getLoginFacade()
{
return loginFacade;
}
public void setLoginFacade(ILogin loginFacade)
{
this.loginFacade = loginFacade;
}
protected Object formBackingObject(HttpServletRequest request)
{
Login login=loginFacade.getLoginCredentials(request.
getParameter("txtUserId"),request.getParameter("pw dPassword"));
session=request.getSession(false);
session.setAttribute("LoginDetails",login);
System.out.println("hre in Login Controller...............");
if(login == null)
{
login=new Login();
}
System.out.println("before returnin...............");
return login;
}
}
------------------------------------------------------------------------------
LoginValidator
------------------------------------------------------------------------------
package com.cons.app.businessobjects;
import org.springframework.validation.Validator;
import org.springframework.validation.Errors;
import org.apache.log4j.Logger;
import com.cons.app.beans.Login;
public class LoginValidator implements Validator
{
private static Logger logger=Logger.getLogger(LoginValidator.class);
public boolean supports(Class aClass)
{
logger.info("Login class of Validator");
return aClass.equals("Login.class");
}
public void validate(Object object,Errors errors)
{
Login login=(Login)object;
System.out.println("IN validator$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$");
if(login==null)
{
logger.info("login is null");
errors.rejectValue("Login","The User Name/Password is Incorrect.");
}
else
{
if(login.getUsername()==null || "".equals(login.getUsername()))
{
logger.info("Invalid User Name");
errors.rejectValue("User Name","Invalid User Name");
}
if(login.getPasswd()==null || "".equals(login.getPasswd()))
{
logger.info("Invalid Password");
errors.rejectValue("Password","Invalid Password");
}
}
}
}
------------------------------------------------------------------------------
and i have Login.java. which is just a pojo with username,password getters and setters
the problem is like when i use <spring:bind path="login.username"> in the jsp page. I am getting 404 error. I am not able to figure out wht the problem is. I tried googling and reading some articles etc. But couldnt solve it. Please if some one can guide me to solve this.. i would be thankful.
the error i am getting in the tomcat console there is also an error regarding the log4j but i think for time being we can ignore it. But the main problem is the 404 error in my loginpage of the application.
---------------------------------------------------------------------
Jun 27, 2007 10:54:50 AM org.apache.catalina.core.StandardHost start
INFO: XML validation disabled
Jun 27, 2007 10:54:50 AM org.apache.catalina.startup.HostConfig deployWAR
INFO: Deploying web application archive f1.war
Jun 27, 2007 10:54:52 AM org.apache.catalina.loader.WebappClassLoader validateJa
rFile
INFO: validateJarFile(D:\apache-tomcat-5.5.23\webapps\f1\WEB-INF\lib\servlet-api
.jar) - jar not loaded. See Servlet Spec 2.3, section 9.7.2. Offending class: ja
vax/servlet/Servlet.class
log4j:WARN No appenders could be found for logger (org.apache.commons.digester.D
igester).
log4j:WARN Please initialize the log4j system properly.
Jun 27, 2007 10:54:54 AM org.apache.catalina.core.StandardContext start
SEVERE: Error listenerStart
Jun 27, 2007 10:54:54 AM org.apache.catalina.core.StandardContext start
SEVERE: Context [/f1] startup failed due to previous errors
Jun 27, 2007 10:54:55 AM org.apache.coyote.http11.Http11BaseProtocol start
INFO: Starting Coyote HTTP/1.1 on http-8080
Jun 27, 2007 10:54:56 AM org.apache.jk.common.ChannelSocket init
INFO: JK: ajp13 listening on /0.0.0.0:8009
Jun 27, 2007 10:54:56 AM org.apache.jk.server.JkMain start
INFO: Jk running ID=0 time=0/78 config=null
Jun 27, 2007 10:54:56 AM org.apache.catalina.storeconfig.StoreLoader load
INFO: Find registry server-registry.xml at classpath resource
Jun 27, 2007 10:54:56 AM org.apache.catalina.startup.Catalina start
INFO: Server startup in 6359 ms
-----------------------------------------------------------------------
Thank you
Regards


Reply With Quote