java - Flow not being sent to controller in spring mvc with hibernate -


this emp-servlet.xml

<?xml version="1.0" encoding="utf-8"?> <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">      <context:component-scan base-package="com.cgi.controller"/>      <bean class="org.springframework.web.servlet.view.internalresourceviewresolver">       <property name="prefix" value="/web-inf/jsps/" />       <property name="suffix" value=".jsp" />    </bean>                      <bean id="ds" class="org.springframework.jdbc.datasource.drivermanagerdatasource">        <property name="driverclassname" value="com.mysql.jdbc.driver" />        <property name="url" value="jdbc:mysql://localhost:3306/tutorial" />        <property name="username" value="root" />        <property name="password" value="tiger" />      </bean>      <bean id="mysessionfactory"  class="org.springframework.orm.hibernate3.localsessionfactorybean">        <property name="datasource" ref="ds"></property>        <property name="mappingresources">          <list><value>employee.hbm.xml</value></list>        </property>        <property name="hibernateproperties">          <props>            <prop key="hibernate.dialect">org.hibernate.dialect.mysqldialect</prop>            <prop key="hibernate.hbm2ddl.auto">update</prop>            <prop key="hibernate.show_sql">true</prop>             </props>        </property>       </bean>      <bean id="hibernatetemplate" class="org.springframework.orm.hibernate3.hibernatetemplate">        <property name="sessionfactory" ref="mysessionfactory"/>     </bean>     <bean id="logindao" class="com.cgi.dao.logindaoimpl">          <property name="ht" ref="hibernatetemplate"></property>       </bean>   </beans>   

this web.xml;

<?xml version="1.0" encoding="utf-8"?> <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">   <display-name>login example</display-name>   <welcome-file-list>     <welcome-file>login-form.jsp</welcome-file>   </welcome-file-list>   <servlet>     <servlet-name>emp</servlet-name>     <servlet-class>org.springframework.web.servlet.dispatcherservlet</servlet-class>     <init-param>       <param-name>contextconfiglocation</param-name>       <param-value>/web-inf/controller-servlet.xml</param-value>     </init-param>     <load-on-startup>1</load-on-startup>   </servlet>   <servlet-mapping>     <servlet-name>emp</servlet-name>     <url-pattern>/</url-pattern>   </servlet-mapping>   <context-param>     <param-name>contextconfiglocation</param-name>     <param-value>/web-inf/emp-servlet.xml</param-value>   </context-param>   <listener>     <listener-class>org.springframework.web.context.contextloaderlistener</listener-class>   </listener> </web-app> 

and controller package com.cgi.controller;

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<employee> b=(list<employee>) d.checkuser(name, password);         system.out.println("hello");         map m=new hashmap();         m.put("msg", "hello"+name);          if(b.size()>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<employee> 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");     } } 

and jsp file

<%@ page language="java" contenttype="text/html; charset=iso-8859-1" pageencoding="iso-8859-1"%> <!doctype html public "-//w3c//dtd html 4.01 transitional//en" "http://www.w3.org/tr/html4/loose.dtd"> <html> <head> <meta http-equiv="content-type" content="text/html; charset=iso-8859-1"> <title>login form</title>  </head> <body>  <form method="post" action="/emp/check">  <center> <pre>  user-name: <input id="name" type="text" name="username" required ><br> password:  <input id="pswd" type="password" name="pass" required><br>  <input type="submit" value="submit"><br>  </pre> </center> </form>  </body> </html> 

the problem jsp noyt going controller although have right mapping scheme in web.xml. have checked sites show same. please if run on system , check .. please revert asap.

error report .

severe: servlet.service() servlet [emp] in context path [/employee_management_tool] threw exception [request processing failed; nested exception java.lang.nullpointerexception] root cause java.lang.nullpointerexception @ com.cgi.controller.employeecontroller.handlerequest(employeecontroller.java:28) @ sun.reflect.nativemethodaccessorimpl.invoke0(native method) @ sun.reflect.nativemethodaccessorimpl.invoke(unknown source) @ sun.reflect.delegatingmethodaccessorimpl.invoke(unknown source) @ java.lang.reflect.method.invoke(unknown source) @ org.springframework.web.bind.annotation.support.handlermethodinvoker.doinvokemethod(handlermethodinvoker.java:710) @ org.springframework.web.bind.annotation.support.handlermethodinvoker.invokehandlermethod(handlermethodinvoker.java:167) @ org.springframework.web.servlet.mvc.annotation.annotationmethodhandleradapter.invokehandlermethod(annotationmethodhandleradapter.java:414) @ org.springframework.web.servlet.mvc.annotation.annotationmethodhandleradapter.handle(annotationmethodhandleradapter.java:402) @ org.springframework.web.servlet.dispatcherservlet.dodispatch(dispatcherservlet.java:771) @ org.springframework.web.servlet.dispatcherservlet.doservice(dispatcherservlet.java:716) @ org.springframework.web.servlet.frameworkservlet.processrequest(frameworkservlet.java:647) @ org.springframework.web.servlet.frameworkservlet.dopost(frameworkservlet.java:563) @ javax.servlet.http.httpservlet.service(httpservlet.java:648) @ javax.servlet.http.httpservlet.service(httpservlet.java:729) @ org.apache.catalina.core.applicationfilterchain.internaldofilter(applicationfilterchain.java:291) @ org.apache.catalina.core.applicationfilterchain.dofilter(applicationfilterchain.java:206) @ org.apache.tomcat.websocket.server.wsfilter.dofilter(wsfilter.java:52) @ org.apache.catalina.core.applicationfilterchain.internaldofilter(applicationfilterchain.java:239) @ org.apache.catalina.core.applicationfilterchain.dofilter(applicationfilterchain.java:206) @ org.apache.catalina.core.standardwrappervalve.invoke(standardwrappervalve.java:212) @ org.apache.catalina.core.standardcontextvalve.invoke(standardcontextvalve.java:106) @ org.apache.catalina.authenticator.authenticatorbase.invoke(authenticatorbase.java:502) @ org.apache.catalina.core.standardhostvalve.invoke(standardhostvalve.java:141) @ org.apache.catalina.valves.errorreportvalve.invoke(errorreportvalve.java:79) @ org.apache.catalina.valves.abstractaccesslogvalve.invoke(abstractaccesslogvalve.java:616) @ org.apache.catalina.core.standardenginevalve.invoke(standardenginevalve.java:88) @ org.apache.catalina.connector.coyoteadapter.service(coyoteadapter.java:521) @ org.apache.coyote.http11.abstracthttp11processor.process(abstracthttp11processor.java:1096) @ org.apache.coyote.abstractprotocol$abstractconnectionhandler.process(abstractprotocol.java:674) @ org.apache.tomcat.util.net.nioendpoint$socketprocessor.dorun(nioendpoint.java:1500) @ org.apache.tomcat.util.net.nioendpoint$socketprocessor.run(nioendpoint.java:1456) @ java.util.concurrent.threadpoolexecutor.runworker(unknown source) @ java.util.concurrent.threadpoolexecutor$worker.run(unknown source) @ org.apache.tomcat.util.threads.taskthread$wrappingrunnable.run(taskthread.java:61) @ java.lang.thread.run(unknown source)

  1. check if u r jsp file in '/web-inf/jsps/' folder.
  2. check web.xml, there 'contextconfiglocation' mentioned twice. see below

    <servlet> <servlet-name>emp</servlet-name> <servlet-class>org.springframework.web.servlet.dispatcherservlet</servlet-class> <init-param>   <param-name>contextconfiglocation</param-name>   <param-value>/web-inf/controller-servlet.xml</param-value> </init-param> <load-on-startup>1</load-on-startup> 

and again value

  <context-param>     <param-name>contextconfiglocation</param-name>     <param-value>/web-inf/emp-servlet.xml</param-value>   </context-param> 

i think u should remove second 1 , correct first 1 value '/web-inf/emp-servlet.xml'.

  1. check u r action in jsp 'action="/emp/check', should 'action=check'

Comments