![](/img/trans.png)
[英]What does servletcontext.getRealPath("/") mean and when should I use it
[英]What does “Context” in “ServletContext” mean?
方法getServletContextName()
返回“Web應用程序”的名稱。 這意味着,“ServletContext”只不過是“Web應用程序”。 好。
API定義:
ServletContextListener接收有關它們所屬的Web應用程序的servlet上下文更改的通知。
“Web應用程序”的“servlet上下文”是什么意思? 實際上“ServletContext”中的“Context”是什么?
這個名字確實是IMO,非常糟糕。
我們必須將ServletContext讀作“基於servlet API的Web應用程序的一般上下文”。 而我們必須將ServletConfig(另一個標准類)讀作“servlet的配置”。
他們應該IMO將ServletContext命名為“WebAppContext”或“ApplicationContext”,將ServletConfig命名為“ServletContext”。
順便說一句,在JSP中,鏈接到JspPage的范圍被命名為“page”; 鏈接到HttpServletRequest的范圍被命名為“request”; 命名為HttpSession的作用域名為“session”,鏈接到ServletContext的作用域名為“”application“。
“上下文”表示..上下文 - 它具有特定Web應用程序的上下文信息和功能:
ServletContext
是Java Web應用程序的上下文(因為它使用servlet)
Context在這里意味着Web應用。
啟動或停止Web App時, ServletContextListener
會收到通知。 這樣,您可以自動運行需要在Web應用程序啟動或停止時運行的任務。
ServletContext是Web應用程序的運行時表示。
ServletContext意味着servlet的Context或Runtime環境。 Servlet在像tomcat這樣的Servlet容器中運行。 Servlet容器創建並提供運行時環境,以便servlet執行並管理其生命周期。 它還包含其他信息,如: -
ServletContext是一個接口,它包含一組與自己的servlet容器通信的方法。
這允許servlet訪問服務器的各個部分進行通信的上下文。
ServletContext的生命周期
現在,同一Web應用程序中的每個servlet和JSP都可以訪問此ServletContext。 ServletConfig與ServletContext
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.