3 Replies Latest reply on Nov 8, 2007 6:10 AM by dmitry.demyankov

    Null pointer exception on <jsp:include>

    parki

      Hello:

      Sorry for the barrage of questions today, but thanks to those helping out - it's super-appreciated.

      I am seeing a NPE when trying to <jsp:include> a file.

      My servlet mapping is:

      <servlet-mapping>
      <servlet-name>FacesServlet</servlet-name>
      <url-pattern>*.jsf</url-pattern>
      </servlet-mapping>

      and my JSF files are *.jsp - all is working fine except when I try an include. Here's the include part:



      <f:view>
      ...
      <jsp:include page="/include/example.jsf" />
      ...

      And the file (/include/example.jsp):

      <f:subview>
      <h:outputText value="TESTING" />
      </f:subview>

      The stack trace is below - it indicates an error on a line pretty far away from the <jsp:include> tag, so I'm stumped. If I change the include to be:

      <jsp:include page="/include/example.jsp" />

      then I get the contents of the file included in my page (with no error) but not processed.

      Any help is appreciated.

      Thanks.

      parki...



      org.apache.jasper.JasperException: An exception occurred processing JSP page /protected/main.jsp at line 50

      47: <rich:toolBar height="30" itemSeparator="line">
      48: <h:outputText value="#{i18n.app_name}" />
      49: <rich:toolBarGroup location="right">
      50: <h:commandButton action="#{visit.changeLocale}" title="submit" value="locale" />
      51: <h:commandButton action="#{authentication.logout}" title="submit" value="logout" />
      52: </rich:toolBarGroup>
      53: </rich:toolBar>


      Stacktrace:
      org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:518)
      org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:411)
      org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)
      org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
      com.sun.faces.context.ExternalContextImpl.dispatch(ExternalContextImpl.java:408)
      com.sun.faces.application.ViewHandlerImpl.executePageToBuildView(ViewHandlerImpl.java:442)
      com.sun.faces.application.ViewHandlerImpl.renderView(ViewHandlerImpl.java:115)
      org.ajax4jsf.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:108)
      org.ajax4jsf.application.AjaxViewHandler.renderView(AjaxViewHandler.java:216)
      com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:106)
      com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:251)
      com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:144)
      javax.faces.webapp.FacesServlet.service(FacesServlet.java:245)
      org.ajax4jsf.webapp.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java:141)
      org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:281)
      com.avaning.webapp.servlet.AuthorizationFilter.doFilter(AuthorizationFilter.java:60)
      org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)

      root cause

      javax.servlet.ServletException: javax.servlet.jsp.JspException: java.lang.NullPointerException
      org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:851)
      org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:784)
      org.apache.jsp.protected_.main_jsp._jspService(main_jsp.java:173)
      org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
      org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:387)
      org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)
      org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
      com.sun.faces.context.ExternalContextImpl.dispatch(ExternalContextImpl.java:408)
      com.sun.faces.application.ViewHandlerImpl.executePageToBuildView(ViewHandlerImpl.java:442)
      com.sun.faces.application.ViewHandlerImpl.renderView(ViewHandlerImpl.java:115)
      org.ajax4jsf.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:108)
      org.ajax4jsf.application.AjaxViewHandler.renderView(AjaxViewHandler.java:216)
      com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:106)
      com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:251)
      com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:144)
      javax.faces.webapp.FacesServlet.service(FacesServlet.java:245)
      org.ajax4jsf.webapp.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java:141)
      org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:281)
      com.avaning.webapp.servlet.AuthorizationFilter.doFilter(AuthorizationFilter.java:60)
      org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)



        • 1. Re: Null pointer exception on <jsp:include>
          dmitry.demyankov

          Can you try using a4j:include instead of jsp:include?

          • 2. Re: Null pointer exception on <jsp:include>
            parki

            Hi Dmitry:

            I changed the line to read <a4j:include viewId="/include/example.jsf" /> and I get the same problem - a null pointer exception.

            A couple points, which might help:

            1. My *.jsp pages look like (simplified):

            <%@ taglib uri="http://richfaces.org/a4j" prefix="a4j" %>
            <%@ taglib uri="http://richfaces.org/rich" prefix="rich" %>
            <%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
            <%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>

            <ui:composition>
            ...

            <f:view>
            ...
            </f:view>

            </ui:composition>


            Is this the usual/recommended way to do things? I suspect the <ui:composition> tag is not needed, but I'm a bit unsure.

            2. I reduced the included file (/include/example.jsp) to just contain:

            <h:outputText value="TESTING" />

            and I still get the null pointer exception.

            I think I'm doing something wrong/amiss in how I'm structuring the pages.

            Any help, as always, appreciated.

            Regards,

            parki...

            • 3. Re: Null pointer exception on <jsp:include>
              dmitry.demyankov

               

              "parki" wrote:
              <a4j:include viewId="/include/example.jsf" />

              Are you trying to include file with name example.jsp? Then you should have in the include code "example.jsp" instead of "example.jsf" - filename should be used, not the mapping from web.xml

              Does it work with
              <h:outputText value="TESTING" />
              inside example.jsp then a4j:include is corrected?