是否可以在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. 是否可以在C++中禁用鍵?
- 4. 是否可以禁用Controls:HoverButton?
- 5. 通過Tomcat 7中的http標題(cookie)禁用jsessionid
- 6. 是當Tomcat重啓後JSESSIONID是創建
- 7. Clojure中,環,Tomcat和JSESSIONID
- 8. Servlet Faces Servlet不可用(richfaces 4,tomcat 7)
- 9. 用戶是否可以禁用html5 sessionStorage?
- 10. 是否可以使用Puppeteer禁用Websocket?
- 11. 是否可以使用JDBC在servlet中執行SQL文件?
- 12. 是否可以在不禁用JavaScript的情況下禁用AJAX?
- 13. 是否可以在NavigationView中禁用可點擊的HeaderLayout?
- 14. 在java GAE中禁用jsessionid url
- 15. 是否可以在Spring,Eclipselink和Tomcat環境中使用@Transational?
- 16. 是否可以在嵌入式Tomcat 7中啓用JMX?
- 17. 未在Tomcat中調用Servlet
- 18. 是否可以禁用mysql子查詢?
- 19. 是否可以禁用所有邊界?
- 20. 是否可以禁用負向索引?
- 21. 處理時是否可以禁用ImageButton?
- 22. 是否可以禁用RESTEasy的RoleBasedSecurityFilter.java?
- 23. 是否可以禁用D的GC?
- 24. 是否可以禁用視圖損失?
- 25. 是否可以從JavaScript內禁用JavaScript?
- 26. 設置JSESSIONID餅乾確保在Tomcat中
- 27. JSESSIONID在Tomcat中過期日期的Cookie
- 28. 是否可以在webdefault.xml中的8888中運行主Servlet和ProxyServlet?
- 29. 是否可以在Visual Studio中啓用禁用的斷點
- 30. 是否可以在iOS應用中禁用音量按鈕?
爲什麼使用重寫時你可以不創建會話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