2011-02-15 4 views
5

내 JSF 2 프로젝트 구조는 다음과 같다 :JSF2 및 Facelets의 - java.io.FileNotFoundException

java.io.FileNotFoundException 
at org.apache.naming.resources.DirContextURLConnection.getInputStream(DirContextURLConnection.java:381) 
at com.sun.faces.facelets.impl.DefaultFaceletCache._getLastModified(DefaultFaceletCache.java:161) 
at com.sun.faces.facelets.impl.DefaultFaceletCache.access$000(DefaultFaceletCache.java:62) 
at com.sun.faces.facelets.impl.DefaultFaceletCache$1.newInstance(DefaultFaceletCache.java:82) 
at com.sun.faces.facelets.impl.DefaultFaceletCache$1.newInstance(DefaultFaceletCache.java:79) 
at com.sun.faces.util.ExpiringConcurrentCache$1.call(ExpiringConcurrentCache.java:99) 
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303) 
at java.util.concurrent.FutureTask.run(FutureTask.java:138) 
at com.sun.faces.util.ExpiringConcurrentCache.get(ExpiringConcurrentCache.java:114) 
at com.sun.faces.facelets.impl.DefaultFaceletCache.getFacelet(DefaultFaceletCache.java:119) 
at com.sun.faces.facelets.impl.DefaultFaceletCache.getFacelet(DefaultFaceletCache.java:62) 
at com.sun.faces.facelets.impl.DefaultFaceletFactory.getFacelet(DefaultFaceletFactory.java:248) 
at com.sun.faces.facelets.impl.DefaultFacelet.include(DefaultFacelet.java:366) 
at com.sun.faces.facelets.impl.DefaultFacelet.include(DefaultFacelet.java:346) 
at com.sun.faces.facelets.impl.DefaultFaceletContext.includeFacelet(DefaultFaceletContext.java:199) 
at com.sun.faces.facelets.tag.ui.CompositionHandler.apply(CompositionHandler.java:155) 
at com.sun.faces.facelets.compiler.NamespaceHandler.apply(NamespaceHandler.java:93) 
at com.sun.faces.facelets.compiler.EncodingHandler.apply(EncodingHandler.java:82) 
at com.sun.faces.facelets.impl.DefaultFacelet.apply(DefaultFacelet.java:152) 
at com.sun.faces.application.view.FaceletViewHandlingStrategy.buildView(FaceletViewHandlingStrategy.java:744) 
at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:100) 
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101) 
at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139) 
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:313) 
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:306) 
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210) 
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:240) 
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:161) 
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:164) 
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100) 
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:541) 
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118) 
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:383) 
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:243) 
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:188) 
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:166) 
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:288) 
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) 
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) 
at java.lang.Thread.run(Thread.java:662) 

:

root 
... 
    WebContent 
     META-INF 
     resources 
     css 
     images 
     javascript 
    templates 
     commonLayout.xhtml 
     footer.xhtml 
     header.xhtml 
    views 
     main 
     index.xhtml 
    WEB-INF 
    index.jsp 

은 내가 http://localhost/home/main/index.jsf에서 내 페이지를 볼 수있는 노력이 오류가 발생 index.xhtml의 내용은 다음과 같습니다.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml" 
xmlns:ui="http://java.sun.com/jsf/facelets" 
xmlns:h="http://java.sun.com/jsf/html" 
xmlns:f="http://java.sun.com/jsf/core"> 

<ui:composition template="templates/commonLayout.xhtml"> 
    <ui:define name="header"> 
     Add your header here or delete to use the default 
    </ui:define> 
    <ui:define name="content"> 
     Add your content here or delete to use the default 
    </ui:define> 
    <ui:define name="footer"> 
     Add your footer here or delete to use the default 
    </ui:define> 
</ui:composition> 
</html> 

지난 2 일간이 문제에 봉착했습니다. 누구든지 문제가 무엇인지 볼 수 있습니까? 전혀 모르겠습니다.

답변

7

두 가지 :

먼저 프로젝트 구조가 잘못되었습니다. 모든 웹 파일은 WebContent 내부에 있어야합니다.

root 
... 
    WebContent 
     META-INF 
     resources 
     css 
     images 
     javascript 
     templates 
     commonLayout.xhtml 
     footer.xhtml 
     header.xhtml 
     views 
     main 
      index.xhtml 
     WEB-INF 
     index.jsp 

그러나 이것은이 예외가 아닌 404 오류를 생성합니다. 그래서 저는 질문을 공식화하는 것이 당신의 부주의라고 가정 할 것입니다.

둘째, ui:composition의 경로가 /으로 시작하는 경우 WebContent를 기준으로합니다. 하지만 /으로 시작하지 않으면 현재 파일과 관련이 있습니다. 현재 가지고있는 것처럼, Facelets는 실제로 틀린 /views/main/templates/commonLayout.xhtml에서 템플릿을로드하려고 시도합니다. 따라서 다음과 같이 template 경로를 수정하십시오.

<ui:composition template="/templates/commonLayout.xhtml"> 
+0

@BalusC 팁 주셔서 감사드립니다. JSF 2 프로젝트 전체 설정에 대해 약간 혼란 스럽습니다. 이 링크 [link] http://www.coreservlets.com/JSF-Tutorial/jsf2/#Overview에 따르면 모든 웹 파일은 WebContent 내부로 이동해야합니다. 다른 링크 [link] http://www.mkyong.com/jsf2/jsf-2-templating-with-facelets-example/는 예제 다운로드에서 WebContent 외부의 웹 파일을 가지고 있습니다. 이 점을보다 명확하게 설명 할 수있는 권위있는 웹 사이트를 가르쳐 주시겠습니까? – ChuongPham

+0

@BalusC 삭제할 수 없으므로 마지막 코멘트를 무시하십시오. 어쨌든 위의 코드 형식이 제대로되지 않았지만 모든 파일은 WebContent 폴더 아래에 있다고 생각합니다. 또한 요구 사항에 따라 리소스, 템플릿,보기 폴더가 WEB-INF 아래에 있어야합니까? 또는 개인적인 취향에 달려 있습니까? – ChuongPham

+0

WebContent 외부에 있지 않습니다. 폴더의 이름은'webapp'입니다. 폴더 이름에 대한 스펙은 없으며 "WebContent"라는 이름은 Eclipse에만 해당됩니다. 결국 servletcontainer의 webapp 루트 폴더에 배포 된 파일입니다. WEB-INF의 경우 WEB-INF의 파일은 공개적으로 액세스 할 수 없지만 서블릿 API 자체 (requestdispatcher, include 등)를 통해 액세스 할 수 있습니다. – BalusC

관련 문제