在我讀的教程中,我遇到了getServletContext(),但這兩個是什麼?
這是該行的樣子:什麼是getServletContextLocal()和getServletContextProvider()
ServletContext sc = getServletContextProvider().getServletContextLocal();
這是如何不同:
ServletContext sc = getServletContext();
在我讀的教程中,我遇到了getServletContext(),但這兩個是什麼?
這是該行的樣子:什麼是getServletContextLocal()和getServletContextProvider()
ServletContext sc = getServletContextProvider().getServletContextLocal();
這是如何不同:
ServletContext sc = getServletContext();
你的回答是特定於可能實現ServletContextProvider
接口的類。爲了正確回答這個問題,您需要提供包含ServletContextProvider
的包,或者更有幫助的包含getServletContextProvider()
和getServletContext()
方法(聲明或抽象)的類或接口。
對我們來說更容易,提供指向您參考的教程的鏈接,或一些額外的上下文(無雙關語)。在互聯網上(在Google搜索之後),只有對getServletContextLocal
方法的引用是這個問題或這個問題的副本。
假設getServletContextProvider()
返回ServletContextProvider
類或接口,有幾個接口和類可用該名稱;我會通過我發現的每一個:
getServletContextLocal()
方法。getServletContextLocal()
方法;所述接口的實現者,LiferayServletContextProvider
沒有getServletContextLocal()
方法,並且擴展了Object。getServletContextLocal()
方法,它的接口也沒有實現,它擴展了Object。getServletContextLocal()
方法,也沒有在該鏈接上列出的4個實現類。getServletContextLocal()
方法,並擴展了Object。getServletContextLocal()
方法。結論:什麼你輸入可能是在你閱讀教程一個錯字,可能參考目前最常用的接口,org.apache.portals.bridges.common.ServletContextProvider
,其中有一個getServletContext(GenericPortlet portlet)
方法。本教程可能要編寫的內容是getServletContextProvider().getServletContext(local)
,其中local
變量是延伸爲javax.portlet.GenericPortlet
的類。然後getServletContext(local)
方法將返回與所述變量相關聯的javax.servlet.ServletContext
。是否與getServletContext()
返回的javax.servlet.ServletContext
相同取決於GenericPortlet
變量的分配位置。
幫你一個忙,並引用你指的教程的位置。
是關於portlet的嗎? – Bozho
我甚至不知道什麼是portlet,我只是看着java中的服務器代碼來弄清楚它是如何工作的,它使用servlets(這是一種初學者) – Kobe
它看起來像portlet。 – Bozho