gpt4 book ai didi

java - 运行简单的 JSF 时出现异常?

转载 作者:行者123 更新时间:2023-11-30 05:14:13 26 4
gpt4 key购买 nike

当我运行 JSF 时,出现以下异常...

异常

 org.apache.jasper.JasperException: javax.servlet.ServletException:
javax.servlet.jsp.JspException: javax.faces.el.EvaluationException:
javax.faces.FacesException: javax.faces.FacesException: Can't instantiate class: ''.
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:522)

org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:398)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
com.sun.faces.context.ExternalContextImpl.dispatch(ExternalContextImpl.java:322)
com.sun.faces.application.ViewHandlerImpl.renderView(ViewHandlerImpl.java:147)
com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:87)
com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:200)
com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:117)
javax.faces.webapp.FacesServlet.service(FacesServlet.java:198)

我的 JSF 代码

<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
<%@ taglib prefix="f" uri="http://java.sun.com/jsf/core"%>
<%@ taglib prefix="h" uri="http://java.sun.com/jsf/html"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<f:view>
<f:loadBundle var="msg" basename="property.menu"/>
<h:form>
<h:selectOneMenu id="Name" value="#{myBean.input}">
<f:selectItem itemLabel="#{msg.Arun}" itemValue="#{msg.Arun}"/>
<f:selectItem itemValue="#{msg.Hari}" itemLabel="#{msg.Hari}"/>
<f:selectItem itemValue="#{msg.Jeya}" itemLabel="#{msg.Jeya}"/>
<f:selectItem itemValue="#{msg.Radhika}" itemLabel="#{msg.Radhika}"/>
<f:selectItem itemValue="#{msg.Karthik}" itemLabel="#{msg.Karthik}"/>
</h:selectOneMenu>
</h:form>
</f:view>
</body>
</html>

我的 faces-config.xml

<faces-config>
<managed-bean>
<managed-bean-name>myBean</managed-bean-name>
<managed-bean-class>mypackage.bean</managed-bean-class>
<managed-bean-scope>request</managed-bean-scope>
</managed-bean>
</faces-config>

Web.xml

<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>0</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.faces</url-pattern>
</servlet-mapping>

最佳答案

至少有两个缺陷:

首先在您的faces-config中:

<managed-bean-class>mypackage.bean</managed-bean-class>

不确定这是否是一个拼写错误,但类名应该以大写字母开头。这只是标准Sun Java Naming Convention 。所以修复它:

<managed-bean-class>mypackage.Bean</managed-bean-class>

如有必要,还将实际类重命名为Bean。然而,这本身并不是这个特定问题的原因,但应该尽快清除不良做法;)

JSF 页面中的第二个:

<h:selectOneMenu id="Name" value="#{myBean.input}">

上面写着 myBean,但您只在 faces 配置中声明了 bean

<managed-bean-name>bean</managed-bean-name>

现在是哪一个? :)

关于java - 运行简单的 JSF 时出现异常?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2227387/

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