Announcement Announcement Module
Collapse
No announcement yet.
not getting session object in Spring mvc Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • not getting session object in Spring mvc

    Hi All
    In my project my requirement is just like that i have to store the login user pojo in session but i am not getting it in my other controller.Pleadse help me out.The code is as follows
    Application context is
    Code:
               <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation="http://www.springframework.org/schema/beans 
    http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
    
    <bean id="loginController" class="cghs.commons.claims.action.LoginController">
    	  <property name="commandClass" value="cghs.commons.claims.teo.UserTeo" />
    	  <property name="formView" value="login" />
    	  <property name="successView" value="hello_world.html"/>
    	  <property name="daoInterface"><ref bean="transactionDAO"/></property>	 
      </bean>
      <bean id="succeessLogin" class="CommonControllerForAll"/>
        <bean id="urlMapping" 	class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping"> 
           <property name="mappings">
    		<props>
    			<prop key="/login.html">loginController</prop>
    			<prop key="/succeessLogin.html">succeessLogin</prop>
    		</props>
    	</property>
      </bean>

    My first controller loginController is as follows

    Code:
      public class LoginController extends SimpleFormController{
    
    @Override
    			public ModelAndView onSubmit(HttpServletRequest request,HttpServletResponse response,Object command,BindException errors) throws ServletException {
    
    UserNicTeo  loginUserTeo = daoInterface.verifyUser(dispensary_code,user,pwd,mopl);
    			
    						HttpSession session = request.getSession(true);
    				System.out.println("Inside the session checking---");
    				if(loginUserTeo !=null && loginUserTeo.getUid().length() > 0){
    					System.out.println("inside the login teo for session");
    					session.setAttribute("loginUserTeo",loginUserTeo);
    				
    			}
    				UserNicTeo  loginUserTeo1 = (UserNicTeo)session.getAttribute("loginUserTeo");
    				System.out.println("User id and password is---"+loginUserTeo1.getDispensary_code());
    mod.setViewName("redirect:succeessLogin.html");
    			
    			System.out.println("Execute succefully");
    And other controller is
    Code:
    public class CommonControllerForAll implements Controller {
    
    	public ModelAndView handleRequest(HttpServletRequest request,
    			HttpServletResponse response) throws Exception {
    		  HttpSession session = request.getSession();
    		  UserNicTeo  loginUserTeo = (UserNicTeo) session.getAttribute("loginUserTeo");
    		 System.out.println("user id in controller  "+loginUserTeo.getUid());
    		 System.out.println("Password in controller  "+loginUserTeo.getPassword());
    		 request.setAttribute("userId", loginUserTeo.getUid());
    		ModelAndView modelAndView = new ModelAndView("successPage");
    		
    		return modelAndView;
    	}
    
    
    // In this controller i am not getting the session data
    Thanks in advance

  • #2
    What is the actual problem? Please post also error message and the Stack Trace if possible. Otherwise your code looks ok.

    Comment

    Working...
    X