HTTP Status 500 : org.apache.jasper.JasperException: java.lang.NullPointerException
<p>i am trying to create a java web app which takes the first name and last name of an actor and lists out all the movie titles that they have acted in.</p>

<p>i am using Glassfish Server 4.1.1
and mysql connector 5.1.39
along with netbeans ide 8.1</p>

<p>this is my startting page index.jsp</p>

<pre><code>&lt;%-- 
    Document   : index
    Created on : Jul 15, 2016, 11:27:47 AM
    Author     : akhilb1
--%&gt;

&lt;%@page contentType="text/html" pageEncoding="UTF-8"%&gt;
&lt;!DOCTYPE html&gt;
&lt;html&gt;
    &lt;head&gt;
        &lt;meta http-equiv="Content-Type" content="text/html; charset=UTF-8"&gt;
        &lt;title&gt;JSP Page&lt;/title&gt;
    &lt;/head&gt;
    &lt;body&gt;
        &lt;h1&gt;Hello World!&lt;/h1&gt;
        &lt;form name="myForm" action="display.jsp" method="POST"&gt;
            &lt;table border="0"&gt;
                &lt;tbody&gt;
                    &lt;tr&gt;
                        &lt;td&gt;First name :&lt;/td&gt;
                        &lt;td&gt;&lt;input type="text" name="first" value="" size="50" /&gt;&lt;/td&gt;
                    &lt;/tr&gt;
                    &lt;tr&gt;
                        &lt;td&gt;Last Name :&lt;/td&gt;
                        &lt;td&gt;&lt;input type="text" name="last" value="" size="50" /&gt;&lt;/td&gt;
                    &lt;/tr&gt;
                &lt;/tbody&gt;
            &lt;/table&gt;
            &lt;input type="reset" value="Clear" name="clear" /&gt;
            &lt;input type="submit" value="Submit" name="submit" /&gt;
        &lt;/form&gt;
    &lt;/body&gt;
&lt;/html&gt;
</code></pre>

<p>and this is my display.jsp page to which the index.jsp sends the request to</p>

<pre><code>&lt;%-- 
    Document   : display
    Created on : Jul 15, 2016, 11:38:53 AM
    Author     : akhilb1
--%&gt;
&lt;%@page import="java.sql.*"%&gt;
&lt;% Class.forName("com.mysql.jdbc.Driver");%&gt;
&lt;%@page contentType="text/html" pageEncoding="UTF-8"%&gt;
&lt;!DOCTYPE html&gt;
&lt;html&gt;
    &lt;head&gt;
        &lt;meta http-equiv="Content-Type" content="text/html; charset=UTF-8"&gt;
        &lt;title&gt;JSP Page&lt;/title&gt;
    &lt;/head&gt;
    &lt;body&gt;
        &lt;h1&gt;Hello World!&lt;/h1&gt;
        &lt;%! 
             public class Actor{

            String URL="jdbc:mysql://localhost:3306/sakila";
            String USERNAME="root";
            String PASSWORD="admin";
            Connection connection =null;
            PreparedStatement selectActors=null;
            ResultSet resultSet = null;



                public Actor(){
                    try {
                    connection=DriverManager.getConnection(URL,USERNAME,PASSWORD);
                    selectActors =connection.prepareStatement(
                                                "SELECT a.first_name,a.last_name,c.title "
                                                +"FROM actor a,film_actor b, film c"
                                                +"WHERE a.first_name=?"
                                                +"AND a.last_name=?"
                                                +"AND a.actor_id=b.actor_id"
                                                +"AND b.film_id=c.film_id");
                    }catch (SQLException e){

                    }
                }
                public ResultSet getACtors(String first,String last){



                    try {
                    selectActors.setString(1,first);
                    selectActors.setString(2,last);


                    resultSet=selectActors.executeQuery();
                    }catch (SQLException e){

                    }

                    return resultSet;
                }


            }
                %&gt;
                &lt;%
                    String firstName= new String();
                    String lastName= new String();

                    if(request.getParameter("first")!=null)
                    {
                        firstName= request.getParameter("first");
                    }
                     if(request.getParameter("last")!=null)
                    {
                        lastName= request.getParameter("last");
                    }

                     Actor actor = new Actor();
                     ResultSet actors= actor.getACtors(firstName,lastName);

                    %&gt;
                    &lt;table border="1"&gt;

                        &lt;tbody&gt;
                            &lt;tr&gt;
                                &lt;td&gt;First Name :&lt;/td&gt;
                                &lt;td&gt;Last Name :&lt;/td&gt;
                                &lt;td&gt;Title&lt;/td&gt;
                            &lt;/tr&gt;
                            &lt;% while (actors.next()) { %&gt;
                            &lt;tr&gt;
                                &lt;td&gt;&lt;%= actors.getString("first_name") %&gt;&lt;/td&gt;
                                &lt;td&gt;&lt;%= actors.getString("last_name") %&gt;&lt;/td&gt;
                                &lt;td&gt;&lt;%= actors.getString("title") %&gt;&lt;/td&gt;
                            &lt;/tr&gt;
                            &lt;% } %&gt;
                        &lt;/tbody&gt;
                    &lt;/table&gt;

        &lt;/body&gt;
    &lt;/html&gt;
</code></pre>

<p>i am using the default database that is given to us by mysql that is sakila upon installing.</p>

<p>both the files are compiling properly 
but when i hit the submit button i get a 
HTTP Status 500 - Internal Server Error</p>

<pre><code>type Exception report

messageInternal Server Error

descriptionThe server encountered an internal error that prevented it from fulfilling this request.

exception 
org.apache.jasper.JasperException: java.lang.NullPointerException


root cause 
java.lang.NullPointerException


note The full stack traces of the exception and its root causes are available in the GlassFish Server Open Source Edition 4.1.1 logs.


GlassFish Server Open Source Edition 4.1.1 
</code></pre>

<p>the logs from the server </p>

<pre><code>Warning:   StandardWrapperValve[jsp]: Servlet.service() for servlet jsp threw exception
java.lang.NullPointerException
    at org.apache.jsp.display_jsp._jspService(display_jsp.java:133)
    at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:111)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
    at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:411)
    at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:473)
    at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:377)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
    at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1682)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:318)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:160)
    at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:734)
    at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:673)
    at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:99)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:174)
    at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:416)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:283)
    at com.sun.enterprise.v3.services.impl.ContainerMapper$HttpHandlerCallable.call(ContainerMapper.java:459)
    at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:167)
    at org.glassfish.grizzly.http.server.HttpHandler.runService(HttpHandler.java:206)
    at org.glassfish.grizzly.http.server.HttpHandler.doHandle(HttpHandler.java:180)
    at org.glassfish.grizzly.http.server.HttpServerFilter.handleRead(HttpServerFilter.java:235)
    at org.glassfish.grizzly.filterchain.ExecutorResolver$9.execute(ExecutorResolver.java:119)
    at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:283)
    at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:200)
    at org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:132)
    at org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:111)
    at org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:77)
    at org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(TCPNIOTransport.java:536)
    at org.glassfish.grizzly.strategies.AbstractIOStrategy.fireIOEvent(AbstractIOStrategy.java:112)
    at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.run0(WorkerThreadIOStrategy.java:117)
    at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.access$100(WorkerThreadIOStrategy.java:56)
    at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy$WorkerThreadRunnable.run(WorkerThreadIOStrategy.java:137)
    at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:591)
    at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:571)
    at java.lang.Thread.run(Thread.java:745)
</code></pre>

<p>how is it possible to resolve this error.
thank you </p>

<p>here is the display_jsp.java</p>

<pre><code>package org.apache.jsp;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.jsp.*;
import java.sql.*;

public final class display_jsp extends org.apache.jasper.runtime.HttpJspBase
    implements org.apache.jasper.runtime.JspSourceDependent {


             public class Actor{

            String URL="jdbc:mysql://localhost:3306/sakila";
            String USERNAME="root";
            String PASSWORD="admin";
            Connection connection =null;
            PreparedStatement selectActors=null;
            ResultSet resultSet = null;

            public Actor(){
                try {
                connection=DriverManager.getConnection(URL,USERNAME,PASSWORD);
                selectActors =connection.prepareStatement(
                                            "SELECT a.first_name,a.last_name,c.title "
                                            +"FROM actor a,film_actor b, film c"
                                            +"WHERE a.first_name=?"
                                            +"AND a.last_name=?"
                                            +"AND a.actor_id=b.actor_id"
                                            +"AND b.film_id=c.film_id");
                }catch (SQLException e){

                }
            }
            public ResultSet getACtors(String first,String last){



                try {
                selectActors.setString(1,first);
                selectActors.setString(2,last);


                resultSet=selectActors.executeQuery();
                }catch (SQLException e){

                }

                return resultSet;
            }


        }

  private static final JspFactory _jspxFactory = JspFactory.getDefaultFactory();

  private static java.util.List&lt;String&gt; _jspx_dependants;

  private org.glassfish.jsp.api.ResourceInjector _jspx_resourceInjector;

  public java.util.List&lt;String&gt; getDependants() {
    return _jspx_dependants;
  }

  public void _jspService(HttpServletRequest request, HttpServletResponse response)
        throws java.io.IOException, ServletException {

    PageContext pageContext = null;
    HttpSession session = null;
    ServletContext application = null;
    ServletConfig config = null;
    JspWriter out = null;
    Object page = this;
    JspWriter _jspx_out = null;
    PageContext _jspx_page_context = null;

    try {
      response.setContentType("text/html;charset=UTF-8");
      response.setHeader("X-Powered-By", "JSP/2.3");
      pageContext = _jspxFactory.getPageContext(this, request, response,
                null, true, 8192, true);
      _jspx_page_context = pageContext;
      application = pageContext.getServletContext();
      config = pageContext.getServletConfig();
      session = pageContext.getSession();
      out = pageContext.getOut();
      _jspx_out = out;
      _jspx_resourceInjector = (org.glassfish.jsp.api.ResourceInjector) application.getAttribute("com.sun.appserv.jsp.resource.injector");

      out.write('\n');
      out.write('\n');
 Class.forName("com.mysql.jdbc.Driver");
      out.write("\n");
      out.write("\n");
      out.write("&lt;!DOCTYPE html&gt;\n");
      out.write("&lt;html&gt;\n");
      out.write("    &lt;head&gt;\n");
      out.write("        &lt;meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\"&gt;\n");
      out.write("        &lt;title&gt;JSP Page&lt;/title&gt;\n");
      out.write("    &lt;/head&gt;\n");
      out.write("    &lt;body&gt;\n");
      out.write("        &lt;h1&gt;Hello World!&lt;/h1&gt;\n");
      out.write("        ");
      out.write("\n");
      out.write("            ");

                String firstName= new String();
                String lastName= new String();

                if(request.getParameter("first")!=null)
                {
                    firstName= request.getParameter("first");
                }
                 if(request.getParameter("last")!=null)
                {
                    lastName= request.getParameter("last");
                }

                 Actor actor = new Actor();
                 ResultSet actors= actor.getACtors(firstName,lastName);


      out.write("\n");
      out.write("                &lt;table border=\"1\"&gt;\n");
      out.write("               \n");
      out.write("                    &lt;tbody&gt;\n");
      out.write("                        &lt;tr&gt;\n");
      out.write("                            &lt;td&gt;First Name :&lt;/td&gt;\n");
      out.write("                            &lt;td&gt;Last Name :&lt;/td&gt;\n");
      out.write("                            &lt;td&gt;Title&lt;/td&gt;\n");
      out.write("                        &lt;/tr&gt;\n");
      out.write("                        ");
 while (actors.next()) { 
      out.write("\n");
      out.write("                        &lt;tr&gt;\n");
      out.write("                            &lt;td&gt;");
      out.print( actors.getString("first_name") );
      out.write("&lt;/td&gt;\n");
      out.write("                            &lt;td&gt;");
      out.print( actors.getString("last_name") );
      out.write("&lt;/td&gt;\n");
      out.write("                            &lt;td&gt;");
      out.print( actors.getString("title") );
      out.write("&lt;/td&gt;\n");
      out.write("                        &lt;/tr&gt;\n");
      out.write("                        ");
 } 
      out.write("\n");
      out.write("                    &lt;/tbody&gt;\n");
      out.write("                &lt;/table&gt;\n");
      out.write("\n");
      out.write("    &lt;/body&gt;\n");
      out.write("&lt;/html&gt;\n");
    } catch (Throwable t) {
      if (!(t instanceof SkipPageException)){
        out = _jspx_out;
        if (out != null &amp;&amp; out.getBufferSize() != 0)
          out.clearBuffer();
        if (_jspx_page_context != null) _jspx_page_context.handlePageException(t);
        else throw new ServletException(t);
      }
    } finally {
      _jspxFactory.releasePageContext(_jspx_page_context);
    }
  }
}
</code></pre>