0
votes

I have three different servers running Tomcat 7. I'm using JDK 7 and Spring framework.

On my development and Production environment, everything is working smoothly, however on the third machine, I'm encountering an issue with detecting sessions.

On the third server, the initial page opens up fine but the following line of code returns null.

    @RequestMapping(value="/getCaptcha",method=RequestMethod.POST)
    public @ResponseBody OutputStream getCaptchaImage(HttpServletRequest request, HttpServletResponse response) throws IOException{

    String stToken = request.getParameter("token");
    OutputStream os = null;

    try{
        HttpSession httpsession = request.getSession(false);
        System.out.println("HttpSession: "+httpsession);
        if(httpsession != null){
            ...
        }
    }
    catch(Exception e){
        e.printStackTrace();
    }

    return os;
}

Here HttpSession is null and it cannot detect the session I previously set with

    HttpSession httpsession = request.getSession(true);

Aside from this, in my entire project the request.getSession(false) is returning null even though the session was previously set.

I'm not sure if I'm missing something since the same code is working perfectly on the other two servers. Any help/guidance/suggestions will be highly appreciated.

1
Just try request.getSession() to fetch session. - user1211
@user1211 request.getSession() will create a new session if no session exists. This is not what he asking. - Chinmay
@Chinmay is correct, I'm trying to get my existing session. - Dhruv Pant
Did you check the configuration of the three Tomcat's is the same? - jlumietu
@jlumietu Is there a particular setting I should be look for? - Dhruv Pant

1 Answers

0
votes

You can simply declare HTTP session in request method of Spring MVC

@RequestMapping("/signup")
public void handleMyRequest(HttpSession session, ...) {
   ...
}

Not sure, whether it fits into your requirements or not. I did it for my project.