1

I have created a simple web application in Netbeans 11 on JDK1.8 and running Glassfish 5.1.0 with just one servlet that redirects to a simple JSP page.

On building and running the application I get the above error when I access http://localhost:8080/MyNews/news. Stacktrace here

visiting unvisited references|#]
  visiting unvisited references|#]
  visiting unvisited references|#]
  Loading application [MyNews] at [/MyNews]|#]
  Loading application MyNews done in 161 ms|#]
  GlassFish Server Open Source Edition  5.1.0  (default-private) startup time : Felix (3,830ms), startup services(6,567ms), total(10,397ms)|#]
  visiting unvisited references|#]
  Grizzly Framework 2.4.4 started in: 62ms - bound to [/0.0.0.0:7676]|#]
  Registered com.sun.enterprise.glassfish.bootstrap.osgi.EmbeddedOSGiGlassFishImpl@77ee25f1 as OSGi service registration: org.apache.felix.framework.ServiceRegistrationImpl@6dd93a21.|#]
  Created HTTP listener http-listener-2 on host/port 0.0.0.0:8181|#]
  JMXStartupService has started JMXConnector on JMXService URL service:jmx:rmi://DESKTOP-QQAVGAD:8686/jndi/rmi://DESKTOP-QQAVGAD:8686/jmxrmi|#]
  Grizzly Framework 2.4.4 started in: 13ms - bound to [/0.0.0.0:8181]|#]
  Created HTTP listener http-listener-1 on host/port 0.0.0.0:8080|#]
  Grizzly Framework 2.4.4 started in: 12ms - bound to [/0.0.0.0:8080]|#]
  visiting unvisited references|#]
  visiting unvisited references|#]
  visiting unvisited references|#]
  visiting unvisited references|#]
  visiting unvisited references|#]
  visiting unvisited references|#]
  visiting unvisited references|#]
  visiting unvisited references|#]
  Loading application [MyNews] at [/MyNews]|#]
  MyNews was successfully deployed in 404 milliseconds.|#]
  Initializing Mojarra 2.3.9 for context ''|#]
  Loading application [__admingui] at [/]|#]
  Loading application __admingui done in 2,712 ms|#]
  Context path from ServletContext:  differs from path from bundle: /|#]
  WebModule[/MyNews] ServletContext.log():Marking servlet ViewNews as unavailable|#]
  StandardWrapperValve[ViewNews]: Allocate exception for servlet ViewNews
java.lang.RuntimeException: 
    at view.ViewNews.<init>(ViewNews.java:1)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
    at com.sun.enterprise.container.common.impl.util.InjectionManagerImpl.createManagedObject(InjectionManagerImpl.java:320)
    at com.sun.enterprise.web.WebContainer.createServletInstance(WebContainer.java:725)
    at com.sun.enterprise.web.WebModule.createServletInstance(WebModule.java:1955)
    at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1262)
    at org.apache.catalina.core.StandardWrapper.allocate(StandardWrapper.java:1069)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:136)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:119)
    at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:611)
    at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:550)
    at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:75)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:114)
    at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:332)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:199)
    at com.sun.enterprise.v3.services.impl.ContainerMapper$HttpHandlerCallable.call(ContainerMapper.java:439)
    at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:144)
    at org.glassfish.grizzly.http.server.HttpHandler.runService(HttpHandler.java:182)
    at org.glassfish.grizzly.http.server.HttpHandler.doHandle(HttpHandler.java:156)
    at org.glassfish.grizzly.http.server.HttpServerFilter.handleRead(HttpServerFilter.java:218)
    at org.glassfish.grizzly.filterchain.ExecutorResolver$9.execute(ExecutorResolver.java:95)
    at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:260)
    at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:177)
    at org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:109)
    at org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:88)
    at org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:53)
    at org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(TCPNIOTransport.java:515)
    at org.glassfish.grizzly.strategies.AbstractIOStrategy.fireIOEvent(AbstractIOStrategy.java:89)
    at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.run0(WorkerThreadIOStrategy.java:94)
    at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.access$100(WorkerThreadIOStrategy.java:33)
    at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy$WorkerThreadRunnable.run(WorkerThreadIOStrategy.java:114)
    at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:569)
    at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:549)
    at java.lang.Thread.run(Thread.java:748)
|#]

Here is the servlet

package view;

import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 *
 * @author korla
 */
@WebServlet(name = "ViewNews", urlPatterns = {"/news"})
public class ViewNews extends HttpServlet {

    /**
     * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
     * methods.
     *
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        response.sendRedirect("news.jsp");
    }

    // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
    /**
     * Handles the HTTP <code>GET</code> method.
     *
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        processRequest(request, response);
    }

    /**
     * Handles the HTTP <code>POST</code> method.
     *
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        processRequest(request, response);
    }

    /**
     * Returns a short description of the servlet.
     *
     * @return a String containing servlet description
     */
    @Override
    public String getServletInfo() {
        return "Short description";
    }// </editor-fold>

}

Here is the JSP

<%-- 
    Document   : news
    Created on : 03-May-2020, 4:54:15 PM
    Author     : korla
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
    </head>
    <body>
        <h1>Hello World!</h1>
    </body>
</html>

Libraries added: javax.servlet.jsp-2.2.0.jar javax.servlet-api-4.0.1.jar

I got the same error when running a full-fledged application which i recently rebuilt on JDK-11 with Tomcat9.0 (without the above jars since tomcat comes with them). Shifted that application to JDK-8 and Glassfish (added these jars) as well and still getting the same error.

MandarK
  • 143
  • 1
  • 8
  • If you select **Tools > Java Platforms** to open the _Java Platform Manager_ window, what version of Java is shown as the "_(Default)_"? in the **Platforms** panel? – skomisa May 09 '20 at 06:16
  • JDK 11. After which I deleted that install and now default is jdk 8 – MandarK May 11 '20 at 11:30
  • I'm having a co-worker with this exact same issue. Has there been a resolution @MandarK ? – Marcel Marino Jan 11 '21 at 21:50

1 Answers1

0

Try to install nb-javac plugin for netbeans: https://blogs.apache.org/netbeans/entry/what-s-nb-javac-in

In my case it solved the isue

Gabriel TheCode
  • 163
  • 2
  • 8