title: Flow not being sent to controller in spring mvc with hibernate
body: <p>This is the emp-servlet.xml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;beans xmlns="http://www.springframework.org/schema/beans"  
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
      xmlns:p="http://www.springframework.org/schema/p"  
      xmlns:mvc="http://www.springframework.org/schema/mvc"
      xmlns:context="http://www.springframework.org/schema/context"  
      xsi:schemaLocation="http://www.springframework.org/schema/beans  
          http://www.springframework.org/schema/beans/spring-beans-3.0.xsd  
          http://www.springframework.org/schema/context  
          http://www.springframework.org/schema/context/spring-context-3.0.xsd"&gt;  
     &lt;context:component-scan base-package="com.cgi.controller"/&gt;  
     &lt;bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"&gt;
        &lt;property name="prefix" value="/WEB-INF/JSPS/" /&gt;
        &lt;property name="suffix" value=".jsp" /&gt;
     &lt;/bean&gt;                  
     &lt;bean id="ds" class="org.springframework.jdbc.datasource.DriverManagerDataSource"&gt;  
       &lt;property name="driverClassName" value="com.mysql.jdbc.Driver" /&gt;  
       &lt;property name="url" value="jdbc:mysql://localhost:3306/tutorial" /&gt;  
       &lt;property name="username" value="root" /&gt;  
       &lt;property name="password" value="tiger" /&gt;  
     &lt;/bean&gt;  
     &lt;bean id="mysessionFactory"  class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"&gt;  
       &lt;property name="dataSource" ref="ds"&gt;&lt;/property&gt;  
       &lt;property name="mappingResources"&gt;  
         &lt;list&gt;&lt;value&gt;Employee.hbm.xml&lt;/value&gt;&lt;/list&gt;  
       &lt;/property&gt;  
       &lt;property name="hibernateProperties"&gt;  
         &lt;props&gt;  
           &lt;prop key="hibernate.dialect"&gt;org.hibernate.dialect.MySQLDialect&lt;/prop&gt;  
           &lt;prop key="hibernate.hbm2ddl.auto"&gt;update&lt;/prop&gt;  
           &lt;prop key="hibernate.show_sql"&gt;true&lt;/prop&gt;     
         &lt;/props&gt;  
       &lt;/property&gt;  
      &lt;/bean&gt; 
      &lt;bean id="hibernateTemplate" class="org.springframework.orm.hibernate3.HibernateTemplate"&gt; 
        &lt;property name="sessionFactory" ref="mysessionFactory"/&gt;
      &lt;/bean&gt;
      &lt;bean id="LoginDao" class="com.cgi.dao.LoginDaoImpl"&gt;  
         &lt;property name="ht" ref="hibernateTemplate"&gt;&lt;/property&gt;  
      &lt;/bean&gt;  
  &lt;/beans&gt;  
  </code></pre>
  
  <p>This is the web.xml;</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" id="WebApp_ID" version="3.1"&gt;
    &lt;display-name&gt;Login Example&lt;/display-name&gt;
    &lt;welcome-file-list&gt;
      &lt;welcome-file&gt;Login-Form.jsp&lt;/welcome-file&gt;
    &lt;/welcome-file-list&gt;
    &lt;servlet&gt;
      &lt;servlet-name&gt;emp&lt;/servlet-name&gt;
      &lt;servlet-class&gt;org.springframework.web.servlet.DispatcherServlet&lt;/servlet-class&gt;
      &lt;init-param&gt;
        &lt;param-name&gt;contextConfigLocation&lt;/param-name&gt;
        &lt;param-value&gt;/WEB-INF/Controller-servlet.xml&lt;/param-value&gt;
      &lt;/init-param&gt;
      &lt;load-on-startup&gt;1&lt;/load-on-startup&gt;
    &lt;/servlet&gt;
    &lt;servlet-mapping&gt;
      &lt;servlet-name&gt;emp&lt;/servlet-name&gt;
      &lt;url-pattern&gt;/&lt;/url-pattern&gt;
    &lt;/servlet-mapping&gt;
    &lt;context-param&gt;
      &lt;param-name&gt;contextConfigLocation&lt;/param-name&gt;
      &lt;param-value&gt;/WEB-INF/emp-servlet.xml&lt;/param-value&gt;
    &lt;/context-param&gt;
    &lt;listener&gt;
      &lt;listener-class&gt;org.springframework.web.context.ContextLoaderListener&lt;/listener-class&gt;
    &lt;/listener&gt;
  &lt;/web-app&gt;
  </code></pre>
  
  <p>And this is my controller package <code>com.cgi.controller</code>;</p>
  
  <pre><code>import javax.servlet.http.HttpServletRequest;
  import javax.servlet.http.HttpServletResponse;
  
  import org.springframework.context.ApplicationContext;
  import org.springframework.context.support.ClassPathXmlApplicationContext;
  import org.springframework.stereotype.Controller;
  import org.springframework.web.bind.annotation.RequestMapping;
  import org.springframework.web.bind.annotation.RequestMethod;
  import org.springframework.web.servlet.ModelAndView;
  
  import com.cgi.beans.Employee;
  import com.cgi.dao.LoginDaoImpl;
  
  import java.util.*;
  
  @Controller
  public class EmployeeController
  {
      LoginDaoImpl d;
  
      @RequestMapping(value="/Check", method=RequestMethod.POST)
      public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception 
      {
          String name=request.getParameter("username");
          String password=request.getParameter("pass");
          List&lt;Employee&gt; b=(List&lt;Employee&gt;) d.checkuser(name, password);
          System.out.println("Hello");
          Map m=new HashMap();
          m.put("msg", "Hello"+name);
  
          if(b.size()&gt;0)
          {
              return new ModelAndView("Success",m);
          }
          else
          {
              return new ModelAndView("Fail");
          }
      }
  
      @RequestMapping(value="/GetAll", method = RequestMethod.POST)
      public ModelAndView getAll(HttpServletRequest request, HttpServletResponse response) throws Exception 
      {
          List&lt;Employee&gt; l=d.getall();
  
          Map m=new HashMap();
          m.put("msg", l);
          return new ModelAndView("AllUsers",m);
      }
  
      @RequestMapping("/Register.htm")
      public ModelAndView register(HttpServletRequest req, HttpServletResponse resp) throws Exception
      {
          ApplicationContext ax=new ClassPathXmlApplicationContext("emp-servlet.xml");
  
          Employee e=(Employee)ax.getBean("d");  
          d.save(e);
  
          return new ModelAndView("AllUsers");
      }
  }
  </code></pre>
  
  <p>And this is the jsp file</p>
  
  <pre><code>&lt;%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%&gt;
  &lt;!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"&gt;
  &lt;html&gt;
  &lt;head&gt;
  &lt;meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"&gt;
  &lt;title&gt;Login Form&lt;/title&gt;
  
  &lt;/head&gt;
  &lt;body&gt;
  
  &lt;form method="post" action="/emp/Check"&gt; 
  &lt;center&gt;
  &lt;pre&gt;
  
  User-Name: &lt;input id="name" type="text" name="username" required &gt;&lt;br&gt;
  Password:  &lt;input id="pswd" type="password" name="pass" required&gt;&lt;br&gt;
  
  &lt;input type="submit" value="Submit"&gt;&lt;br&gt;
  
  &lt;/pre&gt;
  &lt;/center&gt;
  &lt;/form&gt; 
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>The problem is that from jsp it is noyt going to my controller although I have the right mapping scheme in <code>web.xml</code>. I have checked my sites but they all show the same. Please if someone could run it on their system and check it .. Please revert asap.</p>
  
  <p>Error Report .</p>
  
  <p>SEVERE: Servlet.service() for servlet [emp] in context with path [/Employee_Management_Tool] threw exception [Request processing failed; nested exception is java.lang.NullPointerException] with root cause
  java.lang.NullPointerException
      at com.cgi.controller.EmployeeController.handleRequest(EmployeeController.java:28)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
      at java.lang.reflect.Method.invoke(Unknown Source)
      at org.springframework.web.bind.annotation.support.HandlerMethodInvoker.doInvokeMethod(HandlerMethodInvoker.java:710)
      at org.springframework.web.bind.annotation.support.HandlerMethodInvoker.invokeHandlerMethod(HandlerMethodInvoker.java:167)
      at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.invokeHandlerMethod(AnnotationMethodHandlerAdapter.java:414)
      at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.handle(AnnotationMethodHandlerAdapter.java:402)
      at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:771)
      at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:716)
      at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:647)
      at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:563)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:648)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:291)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
      at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
      at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:212)
      at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
      at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
      at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:141)
      at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
      at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:616)
      at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
      at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:521)
      at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1096)
      at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:674)
      at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1500)
      at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1456)
      at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
      at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
      at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
      at java.lang.Thread.run(Unknown Source)</p>