问题描述
是在http请求-响应周期的一部分中创建和销毁了jsp PageContext对象,还是在请求之间对其进行了缓存和重用.
Are jsp PageContext objects created and destroyed as part of the http request-response cycle or are they cached and reused between requests.
PageContext具有生命周期方法,建议在请求之间重用.即initialize(),release().
PageContext has life-cycle methods that suggest reuse between requests. ie initialize(), release().
如果它们被重用,则可能会导致严重的并发问题:如果两个http请求到达,请求同一个jsp页面,并且每个请求都由其自己的线程处理,但是在共享的PageContext对象上设置属性,它们将互相呈现的内容.
If they are reused this could pose serious concurrency problems: if two http requests arrive, requesting the same jsp page, and each request is processed by its own thread, but sets attributes on a shared PageContext object, they will render each others' content.
任何帮助表示赞赏.顺便说一下,我正在使用嵌入在Apache Sling中的servlet容器.
Any help appreciated. By the way I am using the servlet container embedded in Apache Sling.
推荐答案
PageContext仅在您的JSP页面中可用.如果您的请求首先由Servlet处理,然后转发到JSP页面(使用RequestDispatcher.forward),则pageContext仅在此JSP页面上可用,但无法从servlet访问它(因为尚无pageContext)当时).
PageContext are only available from your JSP page. If your request was first handled by the servlet, and then forwarded to JSP page (using RequestDispatcher.forward), pageContext is only available on this JSP page, but there is no way to access it from the servlet (because there was no pageContext yet at that time).
从JSP页面的角度来看,每次调用都会获取新的pageContext.页面上下文可以在内部合并,但不能同时由多个JSP页面共享.
From JSP page point of view, it is getting new pageContext every time it is called. Page contexts may be pooled internally, but not shared by multiple JSP pages at the same time.
initialize
和release
方法具有以下注释:页面或标记库作者不应使用此方法."忘掉它们吧.
initialize
and release
methods have this comment: "This method should not be used by page or tag library authors." Just forget about them.
这篇关于一个jsp PageContext对象的生命周期是什么-它是线程安全的吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!