gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 06:46:25 24 4
gpt4 key购买 nike

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

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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com