0

I'm having this error when I run my application on the Tomcat server. The welcome-file index.html is a HTML file with empty body, perfectly opens when I start the application showing anything, the problem comes when accessing the servlet direction, whatever you do always a NullPointerException occurs.

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" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
    id="WebApp_ID" version="2.5">
    <welcome-file-list>
        <welcome-file>index.html</welcome-file>
    </welcome-file-list>
    <servlet>
        <description></description>
        <display-name>ListaCorreosServlet</display-name>
        <servlet-name>ListaCorreosServlet</servlet-name>
        <servlet-class>comunicacion.ListaCorreosServlet</servlet-class>
    </servlet>
    <servlet-mapping>
        <servlet-name>ListaCorreosServlet</servlet-name>
        <url-pattern>/ListaCorreosServlet</url-pattern>
    </servlet-mapping>
</web-app>

ListaCorreosServlet.java

package comunicacion;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import java.io.IOException;

@WebServlet("/ListaCorreosServlet")
public class ListaCorreosServlet extends HttpServlet {
    private static final long serialVersionUID = 1L;

    public void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        doPost(request, response);
    }

    protected void doPost(HttpServletRequest request,
            HttpServletResponse response) throws ServletException, IOException {
    }

}

Console output

nov 14, 2015 5:22:21 PM org.apache.catalina.core.StandardWrapperValve invoke
GRAVE: Servlet.service() for servlet ListaCorreosServlet throws exception
java.lang.NullPointerException
    at comunicacion.ListaCorreosServlet.doPost(ListaCorreosServlet.java:32)
    at comunicacion.ListaCorreosServlet.doGet(ListaCorreosServlet.java:23)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:622)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:291)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:217)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:142)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
    at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:616)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:518)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1091)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:673)
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1500)
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1456)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
    at java.lang.Thread.run(Thread.java:745)

I don't know if I'm doing something wrong or is another Eclipse bug.

germaaan
  • 39
  • 1
  • 9
  • 1
    You're not running the code you think you're running. Clean, rebuild, redeploy, restart, etc. – BalusC Nov 14 '15 at 16:50
  • @electron: sorry, your guess is nonsense. It doesn't explain the stack trace at all. – BalusC Nov 14 '15 at 16:50
  • try this solution i think it's the same [http://stackoverflow.com/questions/2322031/why-did-servlet-service-for-servlet-jsp-throw-this-exception](http://stackoverflow.com/questions/2322031/why-did-servlet-service-for-servlet-jsp-throw-this-exception) – Abdelhak Nov 14 '15 at 16:52
  • @electron How can an empty throw NPE ??? – Rahman Nov 14 '15 at 16:55
  • @Abdelhak: sorry, your guess is nonsense too. It doesn't explain the stack trace at all. – BalusC Nov 14 '15 at 19:21

1 Answers1

0

Thanks to all. I don't know exactly where was the problem, but creating the servlet with the wizard of Eclipse (which actually generates exactly the same code) works perfectly; which meant, another bug to the list of Eclipse.

By the way, I had tried before to clean and rebuild the application at least a dozen times, both the application and server, but still giving the same error; so that's it, I guess it will be a error of Eclipse.

germaaan
  • 39
  • 1
  • 9