首先,我想告诉您,我已经在SO上浏览了相同的问题很长一段时间但没有任何帮助。我有一个项目,我想让AuthBean
来处理身份验证,但是我一直收到已知错误消息的HTTP 500错误
javax.servlet.ServletException: /login.xhtml @14,45 value="#{authBean.login}": Target Unreachable, identifier 'authBean' resolved to null
我使用GlassFish 4服务器作为Java EE运行时环境。
到目前为止,我已经尝试了
javax.faces.bean.SessionScoped
和javax.enterprise.context.SessionScoped
之间切换。AuthBean.class
是否在class
文件夹中。这是我的档案。任何帮助表示赞赏。
AuthBean.java
package pis.back;
import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import pis.data.Person;
import pis.service.PersonManager;
@ManagedBean(name = "authBean")
@SessionScoped
public class AuthBean {
private boolean loggedIn;
private String login;
private String password;
@EJB
private PersonManager personMgr;
public String getLogin() {
return login;
}
public void setLogin(String login) {
this.login = login;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
/*public boolean isLoggedIn() {
return this.loggedIn;
}*/
public String performLogin() {
if (loggedIn) {
return "error";
}
Person person = personMgr.findByLogin(this.login);
if (person == null || !this.password.equals(person.getPassword())) {
return "error";
}
loggedIn = true;
return "ok";
}
public String performLogout() {
if (!loggedIn) {
return "error";
}
loggedIn = false;
return "ok";
}
}
面-config.xml中
<?xml version="1.0" encoding="UTF-8"?>
<faces-config
xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-facesconfig_2_2.xsd"
version="2.2">
</faces-config>
的web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" id="WebApp_ID" version="3.1">
<display-name>pis</display-name>
<welcome-file-list>
<welcome-file>index.xhtml</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.xhtml</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>*.xhtml</url-pattern>
</servlet-mapping>
<filter>
<filter-name>AuthFilter</filter-name>
<filter-class>pis.back.AuthFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>AuthFilter</filter-name>
<url-pattern>*.xhtml</url-pattern>
<dispatcher>REQUEST</dispatcher>
<dispatcher>FORWARD</dispatcher>
<dispatcher>INCLUDE</dispatcher>
</filter-mapping>
</web-app>
的glassfish-web.xml中
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE glassfish-web-app PUBLIC "-//GlassFish.org//DTD GlassFish Application Server 3.1 Servlet 3.0//EN" "http://glassfish.org/dtds/glassfish-web-app_3_0-1.dtd">
<glassfish-web-app>
<context-root>/pis</context-root>
</glassfish-web-app>
login.xhtml
<?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:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core">
<ui:composition template="template.xhtml">
<ui:define name="title">Login</ui:define>
<ui:define name="content">
<h:form>
<h:panelGrid columns="2">
<h:outputLabel value="Login: "/>
<h:inputText value="#{authBean.login}"/>
<h:outputLabel value="Password: "/>
<h:inputSecret value="#{authBean.password}"/>
<h:commandButton action="#{authBean.performLogin}" value="Login"/>
</h:panelGrid>
</h:form>
</ui:define>
</ui:composition>
</html>
的template.xhtml
<?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:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:p="http://primefaces.org/ui">
<h:head>
<title><ui:insert name="title"/></title>
</h:head>
<h:body>
<div id="header">
Here comes header
</div>
<div id="menu">
Here comes menu
</div>
<div id="content">
<h2><ui:insert name="title"/></h2>
<ui:insert name="content"/>
</div>
<div id="footer">
Here comes footer
</div>
</h:body>
</html>
答案 0 :(得分:0)
由于BalusC建议我完全重新安装GlassFish服务器,它开始重新运行。