Announcement Announcement Module
Collapse
No announcement yet.
SimpleFormController in Loginform problem Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • SimpleFormController in Loginform problem

    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

  • #2
    please repost using [ code][ /code] tags. Your post is well quite underreadable without it.

    Code:
    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
    Your web application doesn't start, turn on debug logging and see what is happening.

    Comment


    • #3
      root cause

      hi,
      I am getting the error as follows. If some one knows the cause of the problem a kind help will be appreciated

      ================================================== ============================
      Error Log.
      ================================================== ============================
      2007-06-28 11:13:15,437 ERROR [org.springframework.web.context.ContextLoader] -
      Context initialization failed
      org.springframework.beans.factory.BeanCreationExce ption: Error creating bean wit
      h name 'LoginController' defined in ServletContext resource [/WEB-INF/f1App-serv
      let.xml]: Initialization of bean failed; nested exception is java.lang.IllegalAr
      gumentException: Validator [com.cons.app.businessobjects.LoginValidator@11756
      a4] does not support command class [com.cons.app.beans.Login]
      Caused by:
      java.lang.IllegalArgumentException: Validator [com.cons.app.businessobjects.L
      oginValidator@11756a4] does not support command class [com.cons.app.beans.Log
      in]
      at org.springframework.web.servlet.mvc.BaseCommandCon troller.initApplica
      tionContext(BaseCommandController.java:304)
      at org.springframework.context.support.ApplicationObj ectSupport.setAppli
      cationContext(ApplicationObjectSupport.java:73)
      at org.springframework.context.support.ApplicationCon textAwareProcessor.
      postProcessBeforeInitialization(ApplicationContext AwareProcessor.java:72)
      at org.springframework.beans.factory.support.Abstract AutowireCapableBean
      Factory.applyBeanPostProcessorsBeforeInitializatio n(AbstractAutowireCapableBeanF
      actory.java:301)
      at org.springframework.beans.factory.support.Abstract AutowireCapableBean
      Factory.initializeBean(AbstractAutowireCapableBean Factory.java:1167)
      at org.springframework.beans.factory.support.Abstract AutowireCapableBean
      Factory.createBean(AbstractAutowireCapableBeanFact ory.java:425)
      at org.springframework.beans.factory.support.Abstract BeanFactory$1.getOb
      ject(AbstractBeanFactory.java:251)
      at org.springframework.beans.factory.support.DefaultS ingletonBeanRegistr
      y.getSingleton(DefaultSingletonBeanRegistry.java:1 56)
      at org.springframework.beans.factory.support.Abstract BeanFactory.getBean
      (AbstractBeanFactory.java:248)
      at org.springframework.beans.factory.support.Abstract BeanFactory.getBean
      (AbstractBeanFactory.java:160)
      at org.springframework.context.support.AbstractApplic ationContext.getBea
      n(AbstractApplicationContext.java:733)
      at org.springframework.web.servlet.handler.AbstractUr lHandlerMapping.reg
      isterHandler(AbstractUrlHandlerMapping.java:256)
      at org.springframework.web.servlet.handler.SimpleUrlH andlerMapping.regis
      terHandlers(SimpleUrlHandlerMapping.java:125)
      at org.springframework.web.servlet.handler.SimpleUrlH andlerMapping.initA
      pplicationContext(SimpleUrlHandlerMapping.java:103 )
      at org.springframework.context.support.ApplicationObj ectSupport.setAppli
      cationContext(ApplicationObjectSupport.java:73)
      at org.springframework.context.support.ApplicationCon textAwareProcessor.
      postProcessBeforeInitialization(ApplicationContext AwareProcessor.java:72)
      at org.springframework.beans.factory.support.Abstract AutowireCapableBean
      Factory.applyBeanPostProcessorsBeforeInitializatio n(AbstractAutowireCapableBeanF
      actory.java:301)
      at org.springframework.beans.factory.support.Abstract AutowireCapableBean
      Factory.initializeBean(AbstractAutowireCapableBean Factory.java:1167)
      at org.springframework.beans.factory.support.Abstract AutowireCapableBean
      Factory.createBean(AbstractAutowireCapableBeanFact ory.java:425)



      ================================================== ============================
      Thank you

      Comment


      • #4
        Please use the [ code][/code] tags when posting code... It makes your post much more readable!!!

        If you read the stacktrace you see that there is something wrong with your validator. The way you check for a class is wrong either use instanceof of isAssignable. I prefer the latter.

        Code:
        Caused by:java.lang.IllegalArgumentException: 
        Validator [com.cons.app.businessobjects.LoginValidator@11756a4] 
        does not support command class [com.cons.app.beans.Login]
        Code:
        return (aClass instanceof Login);
        
        return Login.class.isAssignable(aClass);

        Comment


        • #5
          thanks a lot and my apologies for not using the [code] tags.

          Comment

          Working...
          X