获得异常运行简单的JSF时?

时间:2010-02-09 07:12:34

标签: java jsf

当我运行我的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)

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

1 个答案:

答案 0 :(得分:2)

至少有两个缺陷:

首先在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 config中声明了bean

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

现在是哪一个? :)