Three kinds of attributes in servlet

There are three kinds of attributes in the servlet api.they are seperated ServletContext attribute,ServletRequest attribute and httpsession attribute.they have different accessibility,scope and usage.as follows are they.
First of all,we talk the ServletContext attribute ,any part of the web app could acess it,and its life is the web app's deployed life,only the server or the app goes down,the context could be destroyed,of course,including the attribute in the servletContext.
as for its usage,it can be used to store the resources which you
are intent to share in the entire app,for example,the JNDI lookup names,email address ,etc.In addition,we must be aware of ServletContext attribute being not thread safe. and we always synchronized the ServletContext,instead of synchronized the service method.
Secondly,we step into the HttpSession .it can be asessed by any servlets or jsp which are related with the session.and as to the lifecircle,the session can be destroyed programaticallily,or time out.the session attribute can be used to store the resources which is related to the client's session.what'more,it also is not thread safe.so we also need to control the acess to it.we often synchronized the session..
Finally,we are going to talk the last Request attribute.it can be acessed by any part of app which has a direct access to the request.the request object is destroyed after the service method completes.it can be used to pass the model info from controller to
views.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值