Win a copy of Modern JavaScript for the Impatient this week in the Server-Side JavaScript and NodeJS forum!
    Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

how to resolve this null pointer exception

 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Report post to moderator
my controller Class:


package com.ioola.springwithhibernate.controller;

import com.ioola.springwithhibernate.beans.RegisterBean;
import com.ioola.springwithhibernate.dtos.RegisterDTO;
import com.ioola.springwithhibernate.service.RegisterServiceIntf;
import javax.servlet.http.HttpServletRequest;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

@Controller
public class RegisterController {

@Autowired
private RegisterServiceIntf service;

@RequestMapping(value="register.htm",method= RequestMethod.GET)
public String init(Model model){
model.addAttribute("register", new RegisterBean());
return "register";
}

@RequestMapping(value="register.htm",method= RequestMethod.POST)
public String registerUser(HttpServletRequest request,@ModelAttribute("register") RegisterBean registerBean){

System.out.println(request.getParameter("uName"));
System.out.println(request.getParameter("fName"));
System.out.println(request.getParameter("lName"));
System.out.println(request.getParameter("pwd"));
System.out.println(request.getParameter("email"));

RegisterDTO registerDTO = new RegisterDTO();
BeanUtils.copyProperties(registerBean,registerDTO);
// supplierDTO.setCreatedDate(currentDate);

boolean result = false;
String message;
result=service.saveUser(registerDTO);
message = "User is registered successfully";

System.out.println(result);
request.setAttribute("message", message);
request.setAttribute("result", result);

if(result){

return "login";
}else{
return "success";
}


}

}

my ServiceIntf interface:


package com.ioola.springwithhibernate.service;

import com.ioola.springwithhibernate.dtos.RegisterDTO;

public interface RegisterServiceIntf {

public boolean saveUser(RegisterDTO registerDTO);

}

My Service Class:

@Service
public class RegisterServiceImpl implements RegisterServiceIntf{

@Autowired
private RegisterDaoIntf registerDao;


@Override
public boolean saveUser(RegisterDTO registerDTO) {
return registerDao.saveUser(registerDTO);
}

}

My DAO Class:
@Repository
public class RegisterDao implements RegisterDaoIntf {

@Autowired
private SessionFactory sessionFactory;

@Transactional
public boolean saveUser(RegisterDTO registerDTO) {
Session session = sessionFactory.openSession();
RegisterUser register=new RegisterUser();
System.out.println("save user details");
BeanUtils.copyProperties(registerDTO, register);


session.save( register);

System.out.println(register);
return true;
}

}

my DAO Interface:

public interface RegisterDaoIntf {



public boolean saveUser(RegisterDTO registerDTO);

}

my jsp:

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@taglib uri="http://www.springframework.org/tags/form"; prefix="form" %>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>

<form:form action="register.htm" method="POST" commandName="register">
<form:label path="uName">UserName</form:label>
<form:input path="uName"/><br>
<form:label path="pwd">Password</form:label>
<form:password path="pwd"/><br>
<form:label path="fName">First Name</form:label>
<form:input path="fName"/><br>
<form:label path="lName">Last Name</form:label>
<form:input path="lName"/><br>
<form:label path="email"> Email Id</form:label>
<form:input path="email"/><br>
<input type="submit" value="Register"/>
</form:form>

</body>
</html>
Please rectify the problem and send reback
 
SravanKumar palepalli
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Report post to moderator
my config file:
<?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:context="http://www.springframework.org/schema/context";

xmlns:p="http://www.springframework.org/schema/p";
xmlns:aop="http://www.springframework.org/schema/aop";
xmlns:tx="http://www.springframework.org/schema/tx";
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-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.ioola.springwithhibernate.controller.*,com.ioola.springwithhibernate.pojos.*" /> -->
<bean class="org.springframework.web.servlet.mvc.support.ControllerClassNameHandlerMapping"/>

<!--
Most controllers will use the ControllerClassNameHandlerMapping above, but
for the index controller we are using ParameterizableViewController, so we must
define an explicit mapping for it.
-->
<bean id="urlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
<property name="mappings">
<props>
<prop key="index.htm">indexController</prop>
<prop key="register.htm">registerController</prop>
<prop key="login.htm">loginController</prop>
</props>
</property>
</bean>

<bean id="viewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver"
p:prefix="/WEB-INF/jsp/"
p:suffix=".jsp" />

<!--
The index controller.
-->
<bean name="indexController"
class="org.springframework.web.servlet.mvc.ParameterizableViewController"
p:viewName="index" />
<!-- <bean name="registerController"
class="com.ioola.controller.RegisterController"
p:viewName="register" />-->
<bean id="registerController" class="com.ioola.springwithhibernate.controller.RegisterController"/>
<bean id="loginController" class="com.ioola.springwithhibernate.controller.LoginController" />

</beans>
 
Rancher
Posts: 43016
76
  • Mark post as helpful
  • send pies
  • Report post to moderator
Please do not post the same question multiple times. Let's continue the discussion in this duplicate thread where you got answers already. If you're unclear about those, you can ask follow-up questions there.
 
If you look closely at this tiny ad, you will see five bicycles and a naked woman:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic