title: Enable Session in Apache tomcat
body: <p>I am facing a weird problem in setting session and retrieving it.</p>
  
  <p>I have a Java Spring MVC application. But the client side is not using JSP. It's a separate application developed using AngularJS. While logginng in I am setting the session in login controller.</p>
  
  <pre><code>@RequestMapping(value = "/loginUser", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
  @ResponseBody
  public ObejctResponse loginUser(@RequestBody User user, HttpServletRequest request) {
  
      //code checking username and password
      HttpSession session = request.getSession();
      session.setAttribute(USERID, username);
      session.setAttribute(USER, user);
      session.setAttribute(LOGGED_IN, true);
  
      //code
  }
  </code></pre>
  
  <p>I have interceptor to check whether session is null or not. If its null, it returns false. And in the client side, if it returns nothing it will logout and goto login page.</p>
  
  <pre><code>@Override
      public boolean preHandle(HttpServletRequest request, HttpServletResponse response,
              Object object) throws Exception {
          boolean authenticate=false;
          String pathRequest = request.getPathInfo().toLowerCase();
  
          if(pathRequest.matches(".*(loginuser|logoutuser|switchuser|restservice|resetpassword|changepassword|checkemailid).*")) {
              authenticate = true;
          }
          /* String servletPath = request.getServletPath().toLowerCase();
          if(servletPath.matches(".*(rest).*")) {
              authenticate = true;
          } */
          if(!authenticate) {
              HttpSession session = request.getSession(true); /*don't create if it doesn't exist*/
              if(session.getAttribute(USER) != null) {
                  authenticate = true;
              }
          }
          return authenticate;
      }
  </code></pre>
  
  <p>I tried deploying both wars in my local tomcat and its working fine. </p>
  
  <p>In digital ocean machine when i try to deploy both, it is loggin in, Then when i click on any link, its going to request interceptor and returns false, causing to logout in front end. I skipped request authentication session, then its going to its appropriate  controller , but throwing <strong>null pointer exception</strong> because I am taking userid from session. </p>
  
  <p>In the local it is working fine. But in remote machine its not. I didn't change any configuration other than the port. Which file I have to check and what I have to do to enable the session?</p>
  
  <p>I am using <strong>apache tomcat 7.0.47</strong> on remote machine and <strong>apache tomcat 7.0.53</strong> on local</p>