Eclipse & JSF & Tomcat 6:“未找到 FacesContext”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4556436/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 15:34:33  来源:igfitidea点击:

Eclipse & JSF & Tomcat 6: "FacesContext not found"

eclipsejsftomcatwizard

提问by Atmocreations

Using Eclipse Helios, I tried to start a JSF based project.

使用 Eclipse Helios,我尝试启动一个基于 JSF 的项目。

After having created a new workspace, I installed the web-tools-platform stuff. All using the "Install New Software" in the Help menu, this worked quite well.

创建新工作区后,我安装了 web-tools-platform 的东西。全部使用“帮助”菜单中的“安装新软件”,效果很好。

To start developping for my project, I created a new project using the wizard, with which I downloaded and installed Tomcat 6.0 instance and runtime and configured it with the preset "JavaServer Faces v1.2 Project".

为了开始为我的项目进行开发,我使用向导创建了一个新项目,我使用该向导下载并安装了 Tomcat 6.0 实例和运行时,并使用预设的“JavaServer Faces v1.2 项目”对其进行了配置。

I created one single index.jsp-file (again with the wizard using the JSF-template) and put a JSF-outputText on it.

我创建了一个 index.jsp 文件(再次使用 JSF 模板的向导)并在其上放置了一个 JSF-outputText。

Deploy to the tomcat seems to work. When calling index.jsp in a browser, I get several times the following exception:

部署到 tomcat 似乎有效。在浏览器中调用 index.jsp 时,我多次收到以下异常:

29.12.2010 18:24:00 org.apache.catalina.core.StandardWrapperValve invoke SCHWERWIEGEND: Servlet.service() for servlet jsp threw exception java.lang.RuntimeException: FacesContext not found at javax.faces.webapp.UIComponentClassicTagBase.getFacesContext(UIComponentClassicTagBase.java:321) at javax.faces.webapp.UIComponentClassicTagBase.setJspId(UIComponentClassicTagBase.java:228) at org.apache.jsp.login_jsp._jspx_meth_f_005fview_005f0(login_jsp.java:95) at org.apache.jsp.login_jsp._jspService(login_jsp.java:69) at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70) at javax.servlet.http.HttpServlet.service(HttpServlet.java:717) at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:377) at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313) at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260) at javax.servlet.http.HttpServlet.service(HttpServlet.java:717) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298) at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:852) at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588) at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489) at java.lang.Thread.run(Thread.java:662)

29.12.2010 18:24:00 org.apache.catalina.core.StandardWrapperValve 调用 SCHWERWIEGEND:servlet jsp 的 Servlet.service() 抛出异常 java.lang.RuntimeException:在 javax.faces.webapp.UIComponentClassicTagBase(getFacesContext) 中找不到 FacesContext UIComponentClassicTagBase.java:321) 位于 javax.faces.webapp.UIComponentClassicTagBase.setJspId(UIComponentClassicTagBase.java:228) 位于 org.apache.jsp.login_jsp._jspx_meth_f_005fview_005f0(login_jsp.java.jsp.apachejsp.apachejsp.java:95) (login_jsp.java:69) 在 org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70) 在 javax.servlet.http.HttpServlet.service(HttpServlet.java:717) 在 org.apache.jasper。 servlet.JspServletWrapper.service(JspServletWrapper.java:377) 在 org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313) 在 org.apache。jasper.servlet.JspServlet.service(JspServlet.java:260) 在 javax.servlet.http.HttpServlet.service(HttpServlet.java:717) 在 org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)在 org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) 在 org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233) 在 org.apache.catalina.core.StandardContextValve.invoke (StandardContextValve.java:191) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) at org.apache。 catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298) at org.apache。coyote.http11.Http11Processor.process(Http11Processor.java:852) at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588) at org.apache.tomcat.util.net.JioEndpoint$Worker。在 java.lang.Thread.run(Thread.java:662) 运行(JioEndpoint.java:489)

Every single step I did was a standard-clicking-through-wizards process.

我所做的每一步都是一个标准的点击向导过程。

Any idea why this doesn't seem to work?

知道为什么这似乎不起作用吗?

I can easily post screenshots or file excerpts if that helps, though I don't do it here to avoid overloading the question.

如果有帮助,我可以轻松发布屏幕截图或文件摘录,但我不会在这里这样做以避免使问题过载。



Edit: web.xml编辑:web.xml这个文件直接来自 eclipse,我没有修改它,只是我删除了描述标签以缩短整个内容:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
  <display-name>Stundenplan</display-name>
  <welcome-file-list>
    <welcome-file>index.html</welcome-file>
    <welcome-file>index.htm</welcome-file>
    <welcome-file>index.jsp</welcome-file>
    <welcome-file>default.html</welcome-file>
    <welcome-file>default.htm</welcome-file>
    <welcome-file>default.jsp</welcome-file>
  </welcome-file-list>
  <servlet>
    <servlet-name>Faces Servlet</servlet-name>
    <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
  </servlet>
  <servlet-mapping>
    <servlet-name>Faces Servlet</servlet-name>
    <url-pattern>/faces/*</url-pattern>
  </servlet-mapping>
  <context-param>
    <param-name>javax.servlet.jsp.jstl.fmt.localizationContext</param-name>
    <param-value>resources.application</param-value>
  </context-param>
  <context-param>
    <param-name>javax.faces.STATE_SAVING_METHOD</param-name>
    <param-value>client</param-value>
  </context-param>
  <context-param>
    <param-name>org.apache.myfaces.ALLOW_JAVASCRIPT</param-name>
    <param-value>true</param-value>
  </context-param>
  <context-param>
    <param-name>org.apache.myfaces.PRETTY_HTML</param-name>
    <param-value>true</param-value>
  </context-param>
  <context-param>
    <param-name>org.apache.myfaces.DETECT_JAVASCRIPT</param-name>
    <param-value>false</param-value>
  </context-param>
  <context-param>
    <param-name>org.apache.myfaces.AUTO_SCROLL</param-name>
    <param-value>true</param-value>
  </context-param>
  <listener>
    <listener-class>org.apache.myfaces.webapp.StartupServletContextListener</listener-class>
  </listener>
</web-app>

Already tried setting the url-pattern to <url-pattern>/*</url-pattern>but then it's coming up with the exception "java.lang.NoClassDefFoundError: javax/servlet/jsp/jstl/core/Config"

已经尝试将 url-pattern 设置为<url-pattern>/*</url-pattern>但随后出现异常“java.lang.NoClassDefFoundError: javax/servlet/jsp/jstl/core/Config”



Thanks and regards, Tobias

谢谢和问候,托比亚斯

回答by Atmocreations

The user posted his answer some days ago was completely right (whyever the post was deleted).

用户几天前发布了他的答案是完全正确的(为什么帖子被删除了)。

It's necessary to add the jstl.jar-file to /WEB-INF/libAND in eclipse, you need to add it to the build path

/WEB-INF/libeclipse中需要将jstl.jar文件添加到AND中,需要将其添加到构建路径中

And I didn't understand that if the url-pattern is /faces/*, even if no such folder really needs to exist but you can call the file anyway, e.g. /faces/index.jsp

而且我不明白,如果 url-pattern 是/faces/*,即使确实不需要存在这样的文件夹,但您仍然可以调用该文件,例如/faces/index.jsp

Thanks a lot

非常感谢