Session类中的getDefaultInstance()和getInstance()有什么区别? [英] What is the difference between getDefaultInstance() and getInstance() in Session class?

查看:421
本文介绍了Session类中的getDefaultInstance()和getInstance()有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Session.getDefaultInstance(props, authenticator)getInstance(props, authenticator)有什么区别?通常,您何时会选择一个?

What is the difference between Session.getDefaultInstance(props, authenticator) and getInstance(props, authenticator)? In general, when will you choose one over the other?

我还阅读了

I also read Java doc on getDefaultInstance(props, authenticator), but still couldn't able to make out the difference distinctly/clearly.

希望专家可以帮助我更好地理解这一点.

Hope experts can help me in understanding this better.

更新:触发提出此问题的实际原因是:我们在基于Web的应用程序中的某些地方使用了Session.getDefaultInstance()方法.有时,它会抛出java.lang.SecurityException: Access to default session denied,在快速谷歌搜索时,建议改用Session.getInstance()方法.因此,一个人何时会选择另一个?

UPDATE: Actual reason that triggered to ask this question is: We've used Session.getDefaultInstance() method in some places within our web-based application. Sometimes, it throws java.lang.SecurityException: Access to default session denied, on quick googling, it suggested to use Session.getInstance() method instead. Hence, when one would choose one over the other?

推荐答案

如果阅读文档,将会看到

If you read the documentation, you will see that

getDefaultInstance 获取默认的Session对象.如果尚未设置默认值,则会创建一个新的Session对象并将其安装为默认值.

getDefaultInstance Get the default Session object. If a default has not yet been setup, a new Session object is created and installed as the default.

因此,如果尚不存在,它将调用getInstance()

Therefore, if one does not already exist, it call getInstance()

getInstance 获取一个新的Session对象.

getInstance Get a new Session object.

因此,无论是否已经存在,都会创建一个新的会话对象.

So, a new session object is created, regardless of whether one already exists.

这篇关于Session类中的getDefaultInstance()和getInstance()有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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