`

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.
0
0
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics