[英]JSF: Not Found in ExternalContext as a Resource exception
我現有的應用程序是用某種手工制作的 JSP 編寫的。 它包含一個 class 派生自HttpServlet
處理所有請求和它自己的 HTML 模板語言。 我正在嘗試使用常見的 JSF 模板語法重寫它。 現在我正在嘗試重寫一組頁面。 So I did the following: I registered new servlet entry in web.xml (class - javax.faces.webapp.FacesServlet
, url pattern - /jsp/*
) and put this code in old servlet class:
ExistingServlet::doGet(request, response)
{
// some old code
if(page we are going to is my new page)
{
RequestDispatcher dispatcher = request.getRequestDispatcher("/jsp/myNewPage.xhtml");
dispatcher.forward(request, response);
return;
}
}
但是,如果我要訪問此頁面,則會遇到以下異常:
/myNewPage.xhtml 在 ExternalContext 中找不到作為資源
使用此調用堆棧(最后幾行):
at com.sun.faces.facelets.impl.DefaultFaceletFactory.resolveURL(DefaultFaceletFactory.java:224)
at com.sun.faces.facelets.impl.DefaultFaceletFactory.resolveURL(DefaultFaceletFactory.java:265)
at com.sun.faces.facelets.impl.DefaultFaceletFactory.getMetadataFacelet(DefaultFaceletFactory.java:201)
at com.sun.faces.application.view.ViewMetadataImpl.createMetadataView(ViewMetadataImpl.java:114)
at com.sun.faces.lifecycle.RestoreViewPhase.execute(RestoreViewPhase.java:227)
請告訴我這里有什么問題。
When you map the FacesServlet to the URL pattern /jsp/*
, and access the page /jsp/myNewPage.xhtml
, the associated ResourceResolver will attempt to lookup the resource with path /myNewPage.xhtml
using the ExternalContext
, and in turn the ServletContext
object .
這意味着myNewPage.xhtml
頁面必須存在於WebContent
中,否則將報告錯誤。 通過推斷,您必須將myNewPage.xhtml
頁面放在 WebContent 下,或者使用 servlet 中的/jsp/<sub-directory-path>/myNewPage.xhtml
URL 引用該頁面,其中 sub-directory-path 指的是目錄WebContent 目錄下的路徑。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.