Java Bean getter不返回值

Java Bean getter不返回值,java,jsf,jakarta-ee,jsf-2,Java,Jsf,Jakarta Ee,Jsf 2,我正试图为家庭作业设计一个简单的JavaBean/xhtml设置。实现似乎足够简单,但是我无法让GlassFish从JavaBean中提取信息并在HTML中显示 我编写了代码,然后创建了一个war文件并将其加载到GlassFish autodeploy中 下面是index.xhtml: <?xml version="1.0" encoding="UTF-8"?> <html xmlns="http://www.w3.org/1999/xhtml" xmlns:h="htt

我正试图为家庭作业设计一个简单的JavaBean/xhtml设置。实现似乎足够简单,但是我无法让GlassFish从JavaBean中提取信息并在HTML中显示

我编写了代码,然后创建了一个war文件并将其加载到GlassFish autodeploy中

下面是index.xhtml:

<?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>System information</title>
   </h:head>
   <h:body>
      <h:form>
        <p>           
            This system's java version is #{properties.getJavaVersion}
        </p>
        <p>
        This sytem's OS Name is #{properties.getOsName}
        </p>
        <p>
        This System's OS version is #{properties.getOsVersion}
        </p>
     </h:form>
  </h:body>
</html>
这是我的web.xml文件,位于root/web-INF中/

<?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>

Facesservlet
javax.faces.webapp.FacesServlet
Facesservlet
/面孔/*
faces/index.xhtml
javax.faces.PROJECT_阶段
发展
最后但并非最不重要的一点是,我的faces-config.xml文件位于root/META-INF:

<?xml version="1.0" encoding="UTF-8"?>
<faces-config
   xmlns="http://java.sun.com/xml/ns/javaee"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xsi:schemaLocation="http://java.sun.com/xml/ns/javaee        http://java.sun.com/xml/ns/javaee/web-facesconfig_2_0.xsd"
version="2.0">
</faces-config>


我在屏幕上看到的是“系统的操作系统名称为”,然后是空白。其他两个值也是一样的。我创建了一个传统的应用程序,以确保System.getProperties在我的计算机上正常工作。我还使用不同的字符串初始化了properties.VALUES,只是为了确保。在过去的六个小时里,我一直在用头撞墙。同样,根据我所研究的不同教程、教科书和youtube视频,这一切似乎都有意义。任何洞察都会很棒

使用以下方法访问bean属性是错误的:

应该是

This system's java version is #{properties.javaVersion}
由于
getJavaVersion()
是getter,因此EL将查找
javaVersion
属性。其他领域也是如此。如果您有一个bean类:

public class Foo {
   int bar;

   public int getBar(){
     return bar;
   }
}
bar
属性应该作为
{bean.bar}
访问,您必须使用才能访问bean字段。 这意味着要调用bean的getter,必须使用getter方法,但不使用标准前缀get/is。 因此,您应该在xhtml中使用:

properties.javaVersion
properties.osName
properties.osVersion

请注意,xhtml不会直接从字段中读取值,它只读取getter方法。

在尝试睡眠后,我决定尝试应用这些设置,但仍然不起作用。我决定尝试一个完全准备就绪的设置,我使用教科书作者的逐字记录,将其打包成WAR文件并加载到Glassfish中。这可能是我打包文件的方式吗?我只是在根目录中键入命令“jar csv getProperties.war.”命令。我对这本书附带的软件包做了同样的处理。两个war包都没有正确部署,因为没有一个getter返回任何内容。在我的主机系统上可能需要配置一些基本设置。很抱歉,我使用的命令是:jar cvf getProperties.war。我最终下载了NetBeans并使用它而不是Eclipse。一切都很顺利。谢谢大家。
public class Foo {
   int bar;

   public int getBar(){
     return bar;
   }
}
properties.javaVersion
properties.osName
properties.osVersion