使用FacesServlet时出现NullPointerException

时间:2013-10-27 19:32:25

标签: jsp jsf nullpointerexception

我有一个使用JSF的.jsp文件。我已将javax.faces-2.2.4.jar文件复制到我的WEB-INF / lib文件夹中。当我运行程序时,我得到一个NullPointerException。我不确定是什么导致了这个问题。从一些研究来看,我的web.xml文件可能没有正确设置,但我不确定它应该如何阅读。我会很感激任何方向。

JSP文件:

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!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">
<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>
<title>Fix Connections</title>
</head>
<body>
<f:view>    
<h:form>
<h:outputText value="#{Layout.name}" />
</h:form>                           
</f:view>   
</body>
</html>

Layout.java文件:

package layout;
import javax.faces.component.UIComponent;
public class Layout {   
private String name = null; 
public Layout() {
    name = "Steve";
}   
public void setName(String name) {
    this.name = name;
}    
public String getName() {
    return this.name;
}
}

web.xml文件:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com   /xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
  <display-name>test5</display-name>
<servlet>
<display-name>FacesServlet</display-name>    
<servlet-name>FacesServlet</servlet-name>    
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>    
<load-on-startup>1</load-on-startup>
</servlet>

<servlet-mapping>
<servlet-name>FacesServlet</servlet-name>

<url-pattern>/*.jsp</url-pattern>
</servlet-mapping>
</web-app>

的NullPointerException:

org.apache.jasper.JasperException: An exception occurred processing JSP page /Homepage.jsp at line 39

39: <f:view>    
40: <h:form>
41: <h:outputText value="#{Layout.name}" />
42: </h:form>                           

这是异常堆栈跟踪:

org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:553)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:457)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:391)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)

根本原因是java.lang.NullPointerException

javax.faces.webapp.UIComponentClassicTagBase.setJspId(UIComponentClassicTagBase.java:1856)
    org.apache.jsp.Homepage_jsp._jspx_meth_f_005fview_005f0(Homepage_jsp.java:134)
    org.apache.jsp.Homepage_jsp._jspService(Homepage_jsp.java:102)
    org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:419)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:391)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:722)

0 个答案:

没有答案