1

我有一个使用 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>

布局.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>

空指针异常:

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)
4

0 回答 0