直截了当:只要用户不登录或执行POST操作,就不要让您的应用程序创建会话。不要调用 或 。不要为非登录用户创建或管理会话范围的 Bean。确保您使用的框架不会不必要地创建会话,除非您说这样做。request.getSession()
request.getSession(true)
如果由于应用程序的设计方式或所使用的(MVC)框架的限制/错误,这确实是不可能的,那么您最好的选择是将Googlebot请求重定向到没有JSESSIONID标识符的URL。你可以使用Tuckey的URL重写过滤器(比如说,这是Apache HTTPD众所周知的mod_rewrite
Java变体)。下面是其配置示例页面的相关提取。
隐藏 jsessionid for request from googlebot.
<outbound-rule>
<name>Strip URL Session ID's</name>
<note>
Strip ;jsession=XXX from urls passed through response.encodeURL().
The characters ? and # are the only things we can use to find out where the jsessionid ends.
The expression in 'from' below contains three capture groups, the last two being optional.
1, everything before ;jesessionid
2, everything after ;jesessionid=XXX starting with a ? (to get the query string) up to #
3, everything ;jesessionid=XXX and optionally ?XXX starting with a # (to get the target)
eg,
from index.jsp;jsessionid=sss?qqq to index.jsp?qqq
from index.jsp;jsessionid=sss?qqq#ttt to index.jsp?qqq#ttt
from index.jsp;jsessionid=asdasdasdsadsadasd#dfds - index.jsp#dfds
from u.jsp;jsessionid=wert.hg - u.jsp
from /;jsessionid=tyu - /
</note>
<condition name="user-agent">googlebot</condition>
<from>^(.*?)(?:\;jsessionid=[^\?#]*)?(\?[^#]*)?(#.*)?$</from>
<to>$1$2$3</to>
</outbound-rule>