这是我写的 SCCE。我对 Java Web 应用程序编程完全陌生,这意味着我完全有可能遗漏了一些东西。因此,对于新手前进的任何建议都非常感谢。我也尝试过引用包名称,但没有成功。我应该为 web.xml 中的 Session bean 引用什么吗?因为这些文件是在 WAR 文件里面部署的 EAR 文件。我应该注意,我使用的是 java server faces 和 EE7。
GlassFish4 错误
/index.xhtml @10,78 binding="#{serverSessionBean.time}":目标不可达,标识符 'ServerSessionBean'
索引 欢迎文件
<?xml version='1.0' encoding='UTF-8' ?>
<!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:h="http://xmlns.jcp.org/jsf/html">
<h:head>
<title></title>
</h:head>
<h:body>
The current server time is:
<h:outputText binding="#{serverSessionBean.time}"/>
</h:body>
</html>
服务器会话Bean
package com.incredibleifs;
import java.util.Calendar;
import javax.ejb.Stateless;
import javax.inject.Named;
@Stateless(description = "A stateless session bean to hold server generic business methods such as getting the date and time")
@Named()
public class ServerSessionBean implements ServerSessionBeanLocal {
@Override
public int getTime() {
return Calendar.getInstance().get(Calendar.SECOND);
}
}