mmo*_*hab 19 java session spring spring-mvc jsessionid
我正在使用spring MVC并且在jsessionid中遇到问题,我发现如果在浏览器中没有启用cookie,则会在URL中注入jsessionid,生成类似的URL:
HTTP://本地主机/类别; JSESSIONID = Bsls4aQFXA5RUDcmZKV5iw CID = 13001?
实际上浏览器没有问题,但是当Google抓取我的网站,并且Google抓取工具似乎没有Cookie :)时,他们会将该网站的网址存储在该表单中,而我的网站会显示在搜索结果中,其网址类似于包含jsessionid的网址.
实际上它运行没有任何问题,但我更喜欢在没有jsessionid的情况下将网址显示在Google搜索结果中.
有帮助吗?
Bal*_*usC 19
要点:只要用户不登录或执行POST操作,就不要让你的应用创建会话.不要打电话request.getSession()
或request.getSession(true)
.不要为未登录的用户创建或管理会话范围的bean.确保您使用的框架不会不必要地创建会话,而不是您要这样做.
如果由于您的应用程序的设计方式或由于使用的(MVC)框架的限制/错误而确实不可能,那么您最好的办法是将Googlebot请求重定向到没有JSESSIONID标识符的URL.您可以使用Tuckey的URL重写过滤器(也就是说,Apache HTTPD的Java变体是众所周知的mod_rewrite
).以下是其配置示例页面中的相关摘录.
隐藏来自googlebot的请求的jsessionid.
Run Code Online (Sandbox Code Playgroud)<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>
yka*_*ich 11
Spring可以配置为不这样做: 为什么jsessionid被附加到每个url?
Web应用程序可以配置为阻止它:http: //randomcoder.org/articles/jsessionid-considered-harmful
归档时间: |
|
查看次数: |
36088 次 |
最近记录: |