开发者

Session Variable doesnot persist value in next request in Spring MVC controller

I have application wide single controller.

@RequestMapping(method = RequestMethod.POST,value="services")
@ResponseBody
mwpWebServices(@RequestBody String data, HttpServletRequest request, HttpServletResponse response) throws JSONException, UnknownHostException, MongoException

{
    HttpSession session = request.getSession();

    ......

    String method = jsonObj.getString("method");

    ....

    if(method.equals("login"))
    {
        som开发者_如何学PythoneClassObj.login(params);//which stores some value in session variable "somevar"
    }

    if(method.equals("other"))
    {
        System.out.println(session.getAttributes("somevar"));//coming null
    }
}

now "data" will recieve JSON String and I will parse in into JSONObject that will look like {"method":"login","action":"Auth","params":"Some data"}

now when method is login

i call some method of another class to which I pass session object which store some value in session

but when next time when request comes, session varible doesn't persist value...


if(method.equals("login"))
    {
        someClassObj.login(params);
        //which stores some value in session variable "somevar"
    }

How can it store 'some value in session variable "somevar"' if you don't pass the Session or Request object in?


HttpSession of requires the client i.e. Browser to store the session id in cookie. So my browser's cookie was off, that's why each request was bringing new session id

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜