0

I have an app using Struts2 jsp and java..sessionid is created by container.I want to create my own session id and set to that particular session...just want to overwrite.I have aslo created a filter. session id.any clue

something like

session.setSessionId()

thanks..

4

1 回答 1

1

您可以使用可以实现CookiesAware的CookieInterceptor来执行此操作,然后拦截调用以设置您自己的 sessionId。

编辑:

刚刚意识到 CookieInterceptor 不允许你设置 cookie,所以我做了这样的事情

在我的执行方法中,我Action这样做了:

public String execute() {
        String jSessionId = null;
        for (Cookie c : httpServletRequest.getCookies()) {
            if (c.getName().equals("JSESSIONID"))
                jSessionId = c.getValue();
        }
        System.out.println("Value Found In Request = " + jSessionId);
        jSessionId = "TestingOverrideOfJSessionId";
        Cookie myCookie = new Cookie("JSESSIONID", jSessionId);
        myCookie.setMaxAge(60 * 60 * 24 * 365); // Make the cookie last a year
        httpServletResponse.addCookie(myCookie);

        return SUCCESS;
    }

结果

SessionId 覆盖

于 2012-04-16T08:12:47.320 回答