javax.el.PropertyNotFoundException:无法访问目标,标识符';未注册邮政';已解析为空
我正在尝试实现一个简单的留言簿 当用户单击“提交”时,javax.el.PropertyNotFoundException:无法访问目标,标识符';未注册邮政';已解析为空,java,jsf,jakarta-ee,cdi,Java,Jsf,Jakarta Ee,Cdi,我正在尝试实现一个简单的留言簿 当用户单击“提交”时,UnregisteredUserPostCDIBean应该被实例化。但是,我得到了以下例外情况: javax.servlet.ServletException: /guestbook.xhtml @11,57 value="#{unregisteredUserPost.name}": Target Unreachable, identifier 'unregisteredUserPost' resolved to null 如果你能帮我找
UnregisteredUserPost
CDIBean应该被实例化。但是,我得到了以下例外情况:
javax.servlet.ServletException: /guestbook.xhtml @11,57 value="#{unregisteredUserPost.name}": Target Unreachable, identifier 'unregisteredUserPost' resolved to null
如果你能帮我找到问题的根本原因,我会通知你的
guestbook.xhtml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:h="http://xmlns.jcp.org/jsf/html">
<h:head>
<title>#{msg.page_title}</title>
<link rel="stylesheet" type="text/css" href="css.css"/>
</h:head>
<h:body>
<h:form>
<h:outputText value="#{msg.your_name} "/>
<h:inputText value="#{unregisteredUserPost.name}"/>
<br/><br/>
<h:outputText value="#{msg.your_msg}"/>
<br/>
<h:inputTextarea
rows="5" cols="100" value="#{unregisteredUserPost.content}"/>
<br/><br/>
<h:commandButton
value="#{msg.submit}" action="#{unregisteredUserPost}"/>
</h:form>
</h:body>
</html>
<?xml version="1.0" encoding="UTF-8"?>
<beans 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/beans_1_0.xsd">
</beans>
<?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>guestbook1</display-name>
<welcome-file-list>
<welcome-file>guestbook.xhtml</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>
</web-app>
<?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">
<application>
<locale-config>
<default-locale>en</default-locale>
</locale-config>
<resource-bundle>
<base-name>MessagesBundle</base-name>
<var>msg</var>
</resource-bundle>
</application>
</faces-config>
AbstractPost.java
package learning.javaee.guestbook;
import java.time.OffsetDateTime;
import javax.enterprise.context.SessionScoped;
import javax.inject.Named;
@Named
@SessionScoped
public class UnregisteredUserPost extends AbstractPost {
private String name;
private OffsetDateTime dateTime;
public UnregisteredUserPost() {}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public OffsetDateTime getDateTime() {
return dateTime;
}
public void setDateTime(OffsetDateTime dateTime) {
this.dateTime = dateTime;
}
}
package learning.javaee.guestbook;
import java.io.Serializable;
import java.util.logging.Logger;
import javax.inject.Inject;
import javax.inject.Named;
import javax.interceptor.AroundConstruct;
import javax.interceptor.InvocationContext;
@Named
public abstract class AbstractPost implements Serializable {
private String content;
@Inject
private static Logger log;
@AroundConstruct
private void logConstruction(InvocationContext ic) {
try {
ic.proceed();
log.fine("Created " + getClass().getName());
} catch (Exception e) {
log.severe(e.toString());
}
}
public String getContent() {
return content;
}
public void setContent(String content) {
this.content = content;
}
}
beans.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:h="http://xmlns.jcp.org/jsf/html">
<h:head>
<title>#{msg.page_title}</title>
<link rel="stylesheet" type="text/css" href="css.css"/>
</h:head>
<h:body>
<h:form>
<h:outputText value="#{msg.your_name} "/>
<h:inputText value="#{unregisteredUserPost.name}"/>
<br/><br/>
<h:outputText value="#{msg.your_msg}"/>
<br/>
<h:inputTextarea
rows="5" cols="100" value="#{unregisteredUserPost.content}"/>
<br/><br/>
<h:commandButton
value="#{msg.submit}" action="#{unregisteredUserPost}"/>
</h:form>
</h:body>
</html>
<?xml version="1.0" encoding="UTF-8"?>
<beans 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/beans_1_0.xsd">
</beans>
<?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>guestbook1</display-name>
<welcome-file-list>
<welcome-file>guestbook.xhtml</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>
</web-app>
<?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">
<application>
<locale-config>
<default-locale>en</default-locale>
</locale-config>
<resource-bundle>
<base-name>MessagesBundle</base-name>
<var>msg</var>
</resource-bundle>
</application>
</faces-config>
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:h="http://xmlns.jcp.org/jsf/html">
<h:head>
<title>#{msg.page_title}</title>
<link rel="stylesheet" type="text/css" href="css.css"/>
</h:head>
<h:body>
<h:form>
<h:outputText value="#{msg.your_name} "/>
<h:inputText value="#{unregisteredUserPost.name}"/>
<br/><br/>
<h:outputText value="#{msg.your_msg}"/>
<br/>
<h:inputTextarea
rows="5" cols="100" value="#{unregisteredUserPost.content}"/>
<br/><br/>
<h:commandButton
value="#{msg.submit}" action="#{unregisteredUserPost}"/>
</h:form>
</h:body>
</html>
<?xml version="1.0" encoding="UTF-8"?>
<beans 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/beans_1_0.xsd">
</beans>
<?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>guestbook1</display-name>
<welcome-file-list>
<welcome-file>guestbook.xhtml</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>
</web-app>
<?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">
<application>
<locale-config>
<default-locale>en</default-locale>
</locale-config>
<resource-bundle>
<base-name>MessagesBundle</base-name>
<var>msg</var>
</resource-bundle>
</application>
</faces-config>
客房1
guestbook.xhtml
Facesservlet
javax.faces.webapp.FacesServlet
1.
Facesservlet
*.xhtml
faces config.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:h="http://xmlns.jcp.org/jsf/html">
<h:head>
<title>#{msg.page_title}</title>
<link rel="stylesheet" type="text/css" href="css.css"/>
</h:head>
<h:body>
<h:form>
<h:outputText value="#{msg.your_name} "/>
<h:inputText value="#{unregisteredUserPost.name}"/>
<br/><br/>
<h:outputText value="#{msg.your_msg}"/>
<br/>
<h:inputTextarea
rows="5" cols="100" value="#{unregisteredUserPost.content}"/>
<br/><br/>
<h:commandButton
value="#{msg.submit}" action="#{unregisteredUserPost}"/>
</h:form>
</h:body>
</html>
<?xml version="1.0" encoding="UTF-8"?>
<beans 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/beans_1_0.xsd">
</beans>
<?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>guestbook1</display-name>
<welcome-file-list>
<welcome-file>guestbook.xhtml</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>
</web-app>
<?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">
<application>
<locale-config>
<default-locale>en</default-locale>
</locale-config>
<resource-bundle>
<base-name>MessagesBundle</base-name>
<var>msg</var>
</resource-bundle>
</application>
</faces-config>
EN
消息绑定
味精
看起来您的beans.xml中缺少了bean discovery mode=“all”
。CDI需要这个指令从显式归档注入bean
相关的