为什么要设置一个 JSP 页面 session = “false"?指示? [英] Why set a JSP page session = "false" directive?

查看:20
本文介绍了为什么要设置一个 JSP 页面 session = “false"?指示?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道您什么时候想在 JSP 中设置以下页面指令:

I was wondering when you would want to set the following page directive in a JSP:

<%@ page session="false" %>

我知道它会阻止会话对象的创建,但是您什么时候需要这样做?当 JSP 不需要访问隐式会话时,这是否被认为是最佳实践?

I know that it prevents the creation of the session object, but when would you need to do that? Is it considered a best practice when a JSP does not need to access the implicit session?

注意:我问的原因是因为它在这个 Spring MVC 教程中,我假设 springsource 的人知道他们的东西 - http://blog.springsource.com/2011/01/04/green-beans-getting-started-with-spring-mvc/

推荐答案

一个原因是性能内存.如果您有一个不需要参与会话的页面(例如,about.jspfaq.jsp),那么默认行为是涉及每个会话中的 JSP 会增加创建新会话对象(如果尚不存在)的开销,并且随着更多对象驻留在堆上,内存使用量会增加.

One reason would be performance and memory. If you have a page that doesn't need to be involved in a session (like say, an about.jsp or faq.jsp) then the default behaviour of involving every JSP in a session will impose the overhead of creating a new session object (if one doesn't already exist) and increased memory usage as more objects reside on the heap.

如果单个页面看到来自许多独立用户的高流量以及高跳出率,即他们的用户不会继续浏览而是在查看该页面后立即离开网站,则这种效果将被大大夸大 - 容器将为每个用户创建一个新的会话对象,该对象将永远不会再次使用,并且在超时后最终将被垃圾收集 - 添加到对象创建、内存使用和垃圾收集的头上,而不会为您提供任何实际价值.

This effect will be greatly exaggerated in case of a single page seeing high traffic from many unique users combined with a high bounce rate i.e. they users do not continue to browse but leave the site immediately after viewing that one page- the container will create a new session object per user which will never be used again and will ultimately be garbage collected after it times out - added over head of object creation, memory usage and garbage collection without giving you any real value.

这篇关于为什么要设置一个 JSP 页面 session = “false"?指示?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆