java - 运行 Web 应用程序 - 错误 : package javax. faces.bean 不存在

标签 java web-applications runtime-error

我刚刚接触网络应用程序。 我尝试运行简单的网络应用程序。运行后

javac -d WEB-INF/classes WEB-INF/classes/bigjava/*.java 

我有输出:

nazar_art@nazar-desctop:~/Desktop/Big JAVA/bj4_code/ch24/time$ javac -d WEB-INF/classes WEB-INF/classes/bigjava/*.java
WEB-INF/classes/bigjava/TimeBean.java:6: error: package javax.faces.bean does not exist
import javax.faces.bean.ManagedBean;
                       ^
WEB-INF/classes/bigjava/TimeBean.java:7: error: package javax.faces.bean does not exist
import javax.faces.bean.SessionScoped;
                       ^
WEB-INF/classes/bigjava/TimeBean.java:9: error: cannot find symbol
@ManagedBean
 ^
  symbol: class ManagedBean
WEB-INF/classes/bigjava/TimeBean.java:10: error: cannot find symbol
@SessionScoped
 ^
  symbol: class SessionScoped
4 errors

代码:

package bigjava;

import java.text.DateFormat;
import java.util.Date;
import java.util.TimeZone;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;

@ManagedBean
@SessionScoped
public class TimeBean
{
   private DateFormat timeFormatter;

   /**
      Initializes the formatter.
   */
   public TimeBean()
   {
      timeFormatter = DateFormat.getTimeInstance();
   }

   /**
      Read-only time property.
      @return the formatted time
   */
   public String getTime()
   {
      Date time = new Date();
      String timeString = timeFormatter.format(time);
      return timeString;
   }
}

所有类文件实际上都放置在WEB-INF/classes目录中。 index.html 位于 WEB-INF 中并包含:

<?xml version="1.0" encoding="UTF-8"?>
<html xmlns="http://www.w3.org/1999/xhtml"
   xmlns:h="http://java.sun.com/jsf/html">
   <h:head>
      <title>The time application</title>
   </h:head>
   <h:body>
      <h:form>
         <p>           
            The current time is #{timeBean.time}
         </p>
      </h:form>
   </h:body>
</html>

web.xml 与 classes 处于同一级别,并包含:

<?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"
   version="2.5">
   <servlet>
      <servlet-name>Faces Servlet</servlet-name>
      <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
   </servlet>
   <servlet-mapping>
      <servlet-name>Faces Servlet</servlet-name>
      <url-pattern>/faces/*</url-pattern>
   </servlet-mapping>
   <welcome-file-list>
      <welcome-file>faces/index.xhtml</welcome-file>
   </welcome-file-list>
   <context-param>
      <param-name>javax.faces.PROJECT_STAGE</param-name>
      <param-value>Development</param-value>
   </context-param>
</web-app>

我可能会失去一些东西,但我不知道到底是什么。

有什么建议吗?

最佳答案

您必须将 javax.faces.api jar 文件添加到您的项目中。你可以找到这个库here .

下载此文件后,您必须将其导入到您的项目中并将其添加到您的工件中。

引用此链接Error “package javax.faces.bean does not exist”

关于java - 运行 Web 应用程序 - 错误 : package javax. faces.bean 不存在,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18602732/

相关文章:

ruby-on-rails - 从 Rails 应用程序使用 REST API

vba - 使用 VBA 从安全网站导入 Excel 中的数据时出现运行时错误 438

java - 如何在java程序中使用shell脚本的变量而不将其作为参数传递

java - Spring REST 向客户端抛出异常

java - 从 jar 运行特定的 JMH 基准测试

.net - 如果我从未在我的程序中引用过 System.IO,为什么我的用户会收到错误消息?

installation - 使用 "DownloadString"参数调用 "1"的异常 : "Unable to connect to the remote server"

java - 如何通过左键和右值组合两个 JavaPairRDD

java - 如何构建两个 Wicket 应用程序

testing - 移动跨浏览器网络测试