"ServletContext"中的"Context"是什么意思?
"Context" in "ServletContext" refers to the web app itself. When a web app is started or stopped, a ServletContextListener is notified. This allows tasks to be automatically executed when the web app starts or stops.
The term "servlet context" in the API documentation may seem strange because a web app can also contain non-servlet components. In this context, "servlet context" specifically refers to the configuration defined in the web.xml file of the web app.
解决方法:可以通过阅读API文档,了解ServletContextListener接口的具体用法和功能。此外,还可以查看web.xml文件中的配置,以确定servlet context的具体定义和用途。
"ServletContext"中的"context"是指上下文,它包含了特定Web应用程序的上下文信息和功能:
- 应用程序范围的参数
- 应用程序事件监听器
- 关于应用程序的元数据
"ServletContext"是Java Web应用程序的上下文(因为它使用servlets)。
感谢!但是,“web应用程序”的“servlet上下文”是什么意思?
非常感谢!解释得非常清楚。但是,“ApplicationContext”比“ServletContext”更合适,因为上下文(上下文信息)不仅仅适用于servlet,还适用于JSP。
"servlet上下文"给人一种“为servlet而设计的上下文信息”的感觉。好的。那么我们还有其他不适用于servlet的“上下文信息”吗?
适用于所有应用程序中的servlet。查看ServletContext
的方法,可以获取和设置所有的上下文信息。
顺便说一句,JSP是在后期引入的。最后它们会被编译成servlet。所以从历史和理论上讲,这是正确的。
"ServletContext"中的"Context"是指上下文。这个问题的出现原因是关于Servlet API中的命名问题。原本"ServletContext"应该被命名为"WebAppContext"或者"ApplicationContext",而"ServletConfig"应该被命名为"ServletContext"。在JSP中,与JspPage关联的范围被命名为"page",与HttpServletRequest关联的范围被命名为"request",与HttpSession关联的范围被命名为"session",而与ServletContext关联的范围被命名为"application"。因此,"ServletContext"的命名不太准确,应该考虑将其命名为"WebAppContext"或者"ApplicationContext"。