1

I have a .jsp file that is using JSF. I have copied the javax.faces-2.2.4.jar file to my WEB-INF/lib folder. When I run the program I am getting a NullPointerException. I'm not sure what is causing the issue. From some research it may be my web.xml file is not setup correctly but I'm not sure how it should read. I would appreciate any direction.

JSP File:

<%@ 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 file:

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 file:

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

This is the exception stacktrace:

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)

And the root cause is 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)
Rahul
  • 44,383
  • 11
  • 84
  • 103
Stevenyc091
  • 195
  • 1
  • 2
  • 22
  • possible duplicate of [java.lang.NullPointerException at javax.faces.webapp.UIComponentClassicTagBase.setJspId](http://stackoverflow.com/questions/13032224/java-lang-nullpointerexception-at-javax-faces-webapp-uicomponentclassictagbase-s) – Robin Green Oct 27 '13 at 19:51
  • Hi Robin, I did see that post. However, I'm still not sure if my web.xml file is written correctly. Could you elaborate further on the answer from that post? – Stevenyc091 Oct 27 '13 at 20:31
  • Reading the answer doesn't mean you have applied the solutions posted there. There are two parts: configuring the web.xml file and stop using JSP as view technology for JSF 2. Since this seems to be a hello world example, I recommend you to follow the instructions in [StackOverflow JSF wiki](http://stackoverflow.com/tags/jsf/info). – Luiggi Mendoza Oct 27 '13 at 20:50
  • If you're using JSF 2.2, you should read books/tutorials/resources targeted on JSF 2.2, not on JSF 1.x. JSP is deprecated for long since JSF 2.0. – BalusC Oct 28 '13 at 10:03

0 Answers0