是否可以在tomcat中关闭url中的jsessionid? jsessionid似乎不太适合搜索引擎。是否可以在tomcat servlet中禁用jsessionid?
回答
您可以禁用只使用此过滤器的搜索引擎,但我建议使用它的所有响应,因为它比只是不友好的搜索引擎更糟糕。它暴露了可用于某些安全漏洞的会话ID(more info)。
的Tomcat 6(预6.0.30)
Example config为Tuckey过滤:
<outbound-rule encodefirst="true">
<name>Strip URL Session ID's</name>
<from>^(.*?)(?:\;jsessionid=[^\?#]*)?(\?[^#]*)?(#.*)?$</from>
<to>$1$2$3</to>
</outbound-rule>
的Tomcat 6(6.0.30及以后)
您可以使用disableURLRewriting在上下文配置禁用此行为。
的Tomcat 7和Tomcat 8
从Tomcat 7 onwards您可以添加在会话配置以下。
<session-config>
<tracking-mode>COOKIE</tracking-mode>
</session-config>
对包装在一个HttpServletResponseWrapper
仅仅返回URL从encodeRedirectUrl
,encodeRedirectURL
,encodeUrl
和encodeURL
不变response
所有网址中使用Filter
。从泳池的回答
报价:
可以使用tuckey重写过滤器。
您可以禁用只搜索使用此过滤器 引擎,但我使用它的所有响应的 这更糟糕的不仅仅是搜索引擎不友好 倒是 建议。它公开会话ID ,可用于某些安全 漏洞(更多信息)。
值得一提的是,即使jsessionid不再可见,这仍然允许基于Cookie的会话处理。 (摘自他的另一篇文章:Can I turn off the HttpSession in web.xml?)
PS。我没有足够的评论声望,否则我会将此添加到他的帖子中作为评论。
另外,如果您在Tomcat前面有Apache,则可以使用mod_rewrite过滤器去除jsession。
将以下内容添加到您的apache配置中。
#Fix up tomcat jsession appending rule issue
RewriteRule ^/(.*);jsessionid=(.*) /$1 [R=301,L]
这将做301重定向到没有jsessionid的页面。显然这将完全禁用url jsessionid的,但这是我所需要的。
干杯, 马克
默认情况下,Cookie通常是在Tomcat服务器(你可以明确地通过使用Cookie设置= server.xml中的元素真)启用。启用cookie意味着jsessionID不会附加到URL,因为会话将使用cookie进行管理。 但是,即使在启用cookie后,jsessionID也会附加到第一个请求的URL中,因为Web服务器在该阶段不知道cookie是否已启用。为了消除这种jsessionIDs,您可以使用tuckey重写规则:
您可以在http://javatechworld.blogspot.com/2011/01/how-to-remove-jsessionid-from-url-java.html
<outbound-rule encodefirst="true">
<note>Remove jsessionid from embedded urls - for urls WITH query parameters</note>
<from>^/(.*);jsessionid=.*[?](.*)$</from>
<to encode="false">/$1?$2</to>
</outbound-rule>
<outbound-rule encodefirst="true">
<note>Remove jsessionid from embedded urls - for urls WITHOUT query parameters</note>
<from>^/(.*);jsessionid=.*[^?]$</from>
<to encode="false">/$1</to>
</outbound-rule>
找到更多这方面的信息,您可以在http://javatechworld.blogspot.com/2011/01/how-to-remove-jsessionid-from-url-java.html
找到更多这方面的信息,这是可以做到这在Tomcat的6.0: disableURLRewriting
http://tomcat.apache.org/tomcat-6.0-doc/config/context.html
例如
<?xml version='1.0' encoding='utf-8'?>
<Context docBase="PATH_TO_WEBAPP" path="/CONTEXT" disableURLRewriting="true">
</Context>
在Tomcat的7.0,这是控制与应用程序内执行以下操作: ServletContext.setSessionTrackingModes()
Tomcat的7.0如下了Servlet 3.0规范。
<session-config>
<tracking-mode>COOKIE</tracking-mode>
</session-config>
Tomcat 7和Tomcat 8支持您的web-app web.xml中的上述配置,它会禁用基于URL的会话。
在Tomcat 6.0中,您可以在您的tomcat安装的/ config路径中将disableURLRewriting =“true”用于context.xml中。
http://tomcat.apache.org/tomcat-6.0-doc/config/context.html
context.xml文件
<?xml version='1.0' encoding='utf-8'?>
<!--
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<!-- The contents of this file will be loaded for each web application -->
<Context disableURLRewriting="true">
<!-- Default set of monitored resources -->
<WatchedResource>WEB-INF/web.xml</WatchedResource>
<!-- Uncomment this to disable session persistence across Tomcat restarts -->
<!--
<Manager pathname="" />
-->
<!-- Uncomment this to enable Comet connection tacking (provides events
on session expiration as well as webapp lifecycle) -->
<!--
<Valve className="org.apache.catalina.valves.CometConnectionManagerValve" />
-->
</Context>
...
现在tomcat的输出它的搜索引擎友好...
享受
- 1. Tomcat 6禁用JSESSIONID
- 2. 是否可以在RichFaces中禁用AJAX?
- 3. 是否可以禁用Controls:HoverButton?
- 4. 通过Tomcat 7中的http标题(cookie)禁用jsessionid
- 5. 是当Tomcat重启后JSESSIONID是创建
- 6. 是否可以使用Puppeteer禁用Websocket?
- 7. 是否可以使用JDBC在servlet中执行SQL文件?
- 8. 是否可以在不禁用JavaScript的情况下禁用AJAX?
- 9. 在java GAE中禁用jsessionid url
- 10. 是否可以禁用D的GC?
- 11. 是否可以禁用RESTEasy的RoleBasedSecurityFilter.java?
- 12. 是否可以禁用负向索引?
- 13. 是否可以从JavaScript内禁用JavaScript?
- 14. 设置JSESSIONID饼干确保在Tomcat中
- 15. JSESSIONID在Tomcat中过期日期的Cookie
- 16. 我在哪里可以在Tomcat 6中放置servlet jar文件?
- 17. 如何禁用URL中的struts jsessionid
- 18. 是否可以在Visual Studio中启用禁用的断点
- 19. 在tomcat 6中禁用彗星servlet的输出缓冲
- 20. 是否可以更改JSESSIONID cookie的路径?
- 21. 是否可以在JSESSIONID中追加/预先添加文本字符串?
- 22. 是否可以在显示index.jsp之前调用Servlet
- 23. 是否可以在npm3中禁用平板显示器
- 24. 是否可以在进程中禁用setlocale()?
- 25. 是否可以在浏览器中禁用检查元素?
- 26. 是否可以在Lua中禁用堆栈回溯?
- 27. 是否可以在GDB中创建/删除/禁用多个breskpoints?
- 28. 是否可以在NetBeans 6.8中禁用Symfony框架支持?
- 29. 是否可以在Xcode中禁用Swift文档?
- 30. 是否可以在Windows中禁用Ctrl + V?
为什么使用重写时你可以不创建会话cookie? – 2012-01-18 22:50:19
请查看这个答案的日期。 Tomcat 7和跟踪模式功能在2009年不可用。现在按照版本信息更新。 – Pool 2012-12-20 15:42:38
Tomcat 6支持上下文元素的'disableURLRewriting'属性。请参阅http://tomcat.apache.org/tomcat-6.0-doc/config/context.html – 2014-01-07 15:41:10