Null Pointer Exception on jsf tags when running project on server directly using welcome file [duplicate]

This question already has an answer here:

I have a dynamic web project in Eclipse. I want to make use of welcome files and want login.jsp to run automatically when the url of the project is invoked.

My login.jsp is directly under Web-content.
But when I am trying to do this, I am getting an Exception as follows:

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

20: </head>
21: <body>
22: 
23:     <f:view>
24: 
25:         <jsp:include page="pages/header.jsp"></jsp:include>
26:         


Stacktrace:
    org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:575)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:477)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:395)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:339)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
    org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
root cause

java.lang.NullPointerException
    javax.faces.webapp.UIComponentClassicTagBase.setJspId(UIComponentClassicTagBase.java:1856)
    org.apache.jsp.login_jsp._jspx_meth_f_005fview_005f0(login_jsp.java:163)
    org.apache.jsp.login_jsp._jspService(login_jsp.java:127)
    org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:439)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:395)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:339)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
    org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)

In my web.xml, I have configured welcome-file as follows:

    <welcome-file-list>
        <welcome-file>login.jsp</welcome-file>
      </welcome-file-list>
 <servlet>
    <servlet-name>Faces Servlet</servlet-name>
    <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
  </servlet>
  <servlet-mapping>
    <servlet-name>Faces Servlet</servlet-name>
    <url-pattern>/faces/*</url-pattern>
  </servlet-mapping>

After seeing the exception, I tried to remove <f:view> tag just to test whether it runs without it. Then it started to show error in <h:form> tag.
So I concluded that it is giving exception on jsf tags. But I could not understand why ?

Updates:
1. If I am running login.jsp directly, it is running absolutely fine but when I run the Project, it gives the above said Exception.

  1. This is the url I get when I invoke the Project directly:-

    localhost:port_no/Project_Name/

This is the url I get when I invoke login.jsp separately:

localhost:port_no/Project_Name/faces/login.jsp 

This is the login.jsp file:

<%@ 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"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<title></title>
<link rel="stylesheet" type="text/css"
    href="page-resources/styles/style.css" />
  </head>
<body>

    <f:view>

        <jsp:include page="pages/header.jsp"></jsp:include>

        <center>
            <div id="container">

                <div id="log">
            <h:form>
                <center>
                    <fieldset class="f1">
                        <legend class="l1">Login</legend>
                            <h:panelGrid border="0" columns="1">
                        <h:outputLabel value="User ID" />
                        <h:inputText value="#{loginBean.userId}" required="true"
                                requiredMessage="Please enter the value for User Id" />
                        <h:outputLabel value="Password" />
                        <h:inputSecret value="#{loginBean.password}" required="true"
                            requiredMessage="Please enter the value for Password"/>
            <h:outputLabel styleClass="errorMessage" value="**All fields are Mandatory." />
                    <h:outputLink value="SignUp.jsp">
                    <h:outputText value="New User/Biller? Register Here" styleClass="blck" /></h:outputLink>
                    <h:commandButton styleClass="loginFormButtons" type="submit" value="Login" action="#{loginBean.doLogin}"></h:commandButton>
    <h:commandButton  styleClass="loginFormButtons" onclick="backToHome();" value="Back To Home"></h:commandButton>
                    </h:panelGrid>
     <br>
        <h:messages styleClass="errorMessage"></h:messages>
<h:outputText styleClass="#{loginBean.styleClass}" value="#{loginBean.message}"></h:outputText>
                </fieldset>
</center>
</h:form>
            </div>

        <div id="opac">
            <div class="FAQ">
            <h:outputLink id="FAQlink" value="FAQs.jsp">FAQs</h:outputLink>
            </div>


            <div id="recharge">
            <h:outputLink  style="font-weight:bold;color:#FF0000;
            font-size:25px;" value="#">Re-charge Phone
            or DataCard!!!</h:outputLink>
            </div>

                <div id="page1" style="background-image:url('../page-resources/images/download.jpg');background-size:cover;"></div>
                <div id="enclose">
                <div class="but"><br>
                <h2 style="color:rgb(226,226,226);">Now paying bills is very easy <br>with EPP!!!</h2>
                                <input type="button"  onclick="loginFunc()" value="Login">
                                </div>
                        </div><br>
                    <hr>

                <div class="but" style="margin-top:7%;margin-left:2%;
                height:150px;">
                                    <form style="display:inline;" action="SignUp.jsp" target="_blank">
                <input type="submit" value="Get Started Now" >
                </form>
                </div>

                    </center>
        <jsp:include page="pages/footer.jsp"></jsp:include>
    </f:view>
<script src="../page-resources/scripts/login.js" type="text/javascript"></script>
</body>
</html>


Source: jsp

Leave a Reply