【问题标题】:Access same name cookie in different application tabs在不同的应用程序选项卡中访问同名 cookie
【发布时间】:2015-11-20 10:41:25
【问题描述】:

我有一个在 localhost:8080 上运行的应用程序,它创建了一个名为 jsessionid 的 cookie。现在我需要为在 localhost:8090 上运行的不同应用程序打开另一个选项卡,该应用程序还创建一个具有相同名称的 cookie,即 jsessionid

我需要在第二个应用程序选项卡中访问第一个应用程序选项卡的 cookie..

如何访问这两个 cookie...很多尝试但没有运气...

【问题讨论】:

    标签: java jira confluence jira-plugin


    【解决方案1】:

    您可以编写一个 servlet 过滤器,该过滤器将在页面呈现之前运行(在 atlassian-plugin.xml 中)

    <servlet-filter name="My Filter" i18n-name-key="home-page-redirect-filter.name" key="home-page-redirect-filter" class="mypackage.CookieFilter" location="before-dispatch" weight="100"> <description key="home-page-redirect-filter.description">Some description</description> <url-pattern>WHEN_TO_RUN</url-pattern> <dispatcher>REQUEST</dispatcher> <dispatcher>FORWARD</dispatcher> </servlet-filter>

    然后你就可以拦截cookie了

    public void doFilter(ServletRequest req, ServletResponse resp,
            FilterChain chain) throws IOException, ServletException {
        HttpServletRequest request = (HttpServletRequest) req;
        Cookie[] myCookies=request.getCookies();
        //do something with cookies
    }
    

    【讨论】:

    • 嗨 Panos .. 感谢您的快速回复,按照您的建议实施,但仍然没有获得以前的应用程序选项卡 (localhost:8080) cookie,我认为这是因为请求从 localhost:8090 请求的对象...我如何从浏览器中获取它....
    • 对于两个应用程序都有 上下文路径 .. 是否有助于获取 cookie..
    【解决方案2】:

    看来我误读了您的问题。 JSESSIONID 是一个 httponly cookie,您将无法在 javascript 中使用 document.cookie 来获取它。 不妨看看Jsoup Cookies for HTTPS scrapingSending POST request with username and password and save session cookie 了解一些想法。

    【讨论】:

      猜你喜欢
      • 2012-12-10
      • 2020-08-27
      • 1970-01-01
      • 1970-01-01
      • 2021-08-24
      • 2020-12-22
      • 1970-01-01
      • 2011-06-20
      • 1970-01-01
      相关资源
      最近更新 更多