【问题标题】:Cannot get rid of #.{jsessionid} in urls无法摆脱网址中的 #.{jsessionid}
【发布时间】:2012-09-28 12:03:14
【问题描述】:

到目前为止,我已经尝试了两种方法:
-1。添加到 web.xml:

<session-config>
    <tracking-mode>COOKIE</tracking-mode>
</session-config>

-2。使用漂亮的面孔,添加到 pretty-config.xml:

<rewrite match="(?i)^(.*)#\.\w+(.*)" substitute="$1$2" redirect="301"/>

-3。码头专用。添加到 web.xml:

<context-param>
    <param-name>org.eclipse.jetty.servlet.SessionIdPathParameterName</param-name>
    <param-value>none</param-value>
</context-param>

没有任何帮助。 我也无法理解,“#.{jsessionid}”和“jsessionid={jsessionid}”格式(其中 {jsessionid} 是一些看起来像哈希的字符串)有什么区别?

编辑1:
它看起来像片段 ID。他在我所有的网址上做什么?

【问题讨论】:

    标签: jsf-2 servlet-3.0 jsessionid prettyfaces jetty-8


    【解决方案1】:

    除了 alehro 所说的之外,Rewrite 可能更适合您通过从 URL 中删除会话 ID 和其他此类自定义任务来尝试执行的操作。该配置更具声明性和功能性,但也更加冗长。

    下面是使用 //Rewrite 做同样事情的方法。

    @Override
    public Configuration getConfiguration(final ServletContext context)
    {
       return ConfigurationBuilder.begin()
          .addRule()
            .when(Direction.isInbound()
              .and(URL.matches("{p}{sessionID}{s}")))
            .perform(Redirect.temporary("{p}{s}"))
            .where("sessionID").matches("#\\.\\w+");
    }      
    

    URL 参数默认匹配.*,因此前缀和后缀 (p) 和 (s) 不需要额外配置。

    【讨论】:

    • 嗨@林肯。可以把.where()放在.perform()之后吗?
    • 是的,API 非常严格,并且按类型强制执行顺序。如果它按该顺序编译,它可以工作:)
    • where() 子句本质上是规则中出现的参数配置。
    • 感谢您的回复@Lincoln。但是当我使用你的代码时,我得到找不到符号:方法 where(String)。当我查看matches() 方法时,我看到它返回一个URL,而这个抽象没有where() 方法,这个方法属于ConfigurationRuleBuilder。我弄错了吗? (并且您在 where() 行中有额外的右括号)。
    • 道歉。看起来我的示例代码来自一个非常旧的 Rewrite 版本。我在原始答案中修复了它!代码现在应该可以工作了。谢谢你的提问。哈!
    【解决方案2】:

    这个哈希不是 jsessionid。它由 addthis 跟踪附加。要禁用它,请使用:

    <script type="text/javascript">
    var addthis_config = {
    "data_track_addressbar" : false
    };
    </script>
    

    我不知道,也许最好删除这个问题,因为它有点愚蠢。

    【讨论】:

      猜你喜欢
      • 2022-01-09
      • 2020-11-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-10-14
      • 1970-01-01
      • 2015-04-06
      • 2013-06-20
      相关资源
      最近更新 更多