Click here to Skip to main content
15,868,016 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
The build is successful but I am unable to run the servlet as
whenever I try to run I get 500-Internal Server error.
Error snapshot attached for reference. It's giving some runtime exception.

NetBeans IDE - 12.2
Apache Server - 9.0.22
*********************************************************************
Error in Apache log

<pre>20-Jan-2022 00:22:38.623 INFO [main] org.apache.catalina.core.ApplicationContext.log ContextListener: contextInitialized()
20-Jan-2022 00:22:38.623 INFO [main] org.apache.catalina.core.ApplicationContext.log SessionListener: contextInitialized()
20-Jan-2022 00:22:38.626 INFO [main] org.apache.catalina.core.ApplicationContext.log ContextListener: attributeAdded('StockTicker', 'async.Stockticker@7bc10d84')
20-Jan-2022 00:26:59.360 INFO [main] org.apache.catalina.core.ApplicationContext.log SessionListener: contextDestroyed()
20-Jan-2022 00:26:59.360 INFO [main] org.apache.catalina.core.ApplicationContext.log ContextListener: contextDestroyed()
20-Jan-2022 00:27:13.113 INFO [main] org.apache.catalina.core.ApplicationContext.log ContextListener: contextInitialized()
20-Jan-2022 00:27:13.113 INFO [main] org.apache.catalina.core.ApplicationContext.log SessionListener: contextInitialized()
20-Jan-2022 00:27:13.116 INFO [main] org.apache.catalina.core.ApplicationContext.log ContextListener: attributeAdded('StockTicker', 'async.Stockticker@6d24ffa1')
20-Jan-2022 00:29:52.235 INFO [main] org.apache.catalina.core.ApplicationContext.log SessionListener: contextDestroyed()
20-Jan-2022 00:29:52.235 INFO [main] org.apache.catalina.core.ApplicationContext.log ContextListener: contextDestroyed()
20-Jan-2022 00:31:24.516 INFO [main] org.apache.catalina.core.ApplicationContext.log ContextListener: contextInitialized()
20-Jan-2022 00:31:24.516 INFO [main] org.apache.catalina.core.ApplicationContext.log SessionListener: contextInitialized()
20-Jan-2022 00:31:24.519 INFO [main] org.apache.catalina.core.ApplicationContext.log ContextListener: attributeAdded('StockTicker', 'async.Stockticker@7d3430a7')
20-Jan-2022 00:31:38.775 INFO [main] org.apache.catalina.core.ApplicationContext.log SessionListener: contextDestroyed()
20-Jan-2022 00:31:38.775 INFO [main] org.apache.catalina.core.ApplicationContext.log ContextListener: contextDestroyed()
20-Jan-2022 02:38:25.531 INFO [main] org.apache.catalina.core.ApplicationContext.log ContextListener: contextInitialized()
20-Jan-2022 02:38:25.531 INFO [main] org.apache.catalina.core.ApplicationContext.log SessionListener: contextInitialized()
20-Jan-2022 02:38:25.534 INFO [main] org.apache.catalina.core.ApplicationContext.log ContextListener: attributeAdded('StockTicker', 'async.Stockticker@6f603e89')
20-Jan-2022 02:38:34.332 INFO [http-nio-9494-exec-5] org.apache.catalina.core.ApplicationContext.log Marking servlet [first] as unavailable
20-Jan-2022 02:38:34.333 SEVERE [http-nio-9494-exec-5] org.apache.catalina.core.StandardWrapperValve.invoke Allocate exception for servlet [first]
java.lang.RuntimeException:
at com.servlets.FirstServlet.<init>(FirstServlet.java:1)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:64)
at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:500)
at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:481)
at org.apache.catalina.core.DefaultInstanceManager.newInstance(DefaultInstanceManager.java:151)
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1030)
at org.apache.catalina.core.StandardWrapper.allocate(StandardWrapper.java:761)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:135)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:490)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:139)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:678)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:74)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343)
at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:408)
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:853)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1587)
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1130)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:630)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.base/java.lang.Thread.run(Thread.java:832)</pre>


*******************************************************************
Servlet Code (FirstServlet.java)

package com.servlets;
import java.io.IOException;
import javax.servlet.*;

public class FirstServlet implements Servlet{

ServletConfig conf;

public void init(ServletConfig conf)
{
this.conf = conf;
System.out.println("Creating servlet object...");
}

public void service(ServletRequest req, ServletResponse resp) throws ServletException, IOException
{
System.out.println("Service method is running...");
}

public void destroy()
{
System.out.println("Gonna destroy servlet object now...");
}

public ServletConfig getServletConfig()
{
return this.conf;
}

public String getServletInfo()
{
return "First servlet application created by me";
}
}

********************************************************

web.xml

<?xml version="1.0" encoding="UTF-8"?>

<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
version="3.1">

<servlet>
<servlet-name>first</servlet-name>
<servlet-class>com.servlets.FirstServlet</servlet-class>
</servlet>

<servlet-mapping>
<servlet-name>first</servlet-name>
<url-pattern>/web</url-pattern>
</servlet-mapping>

<session-config>
<session-timeout>
30
</session-timeout>
</session-config>
</web-app>

********************************************************
<pre>
index.html

<!DOCTYPE html>
<!--
To change this license header, choose License Headers in Project Properties.
To change this template file, choose Tools | Templates
and open the template in the editor.
-->
<html>
<head>
<title>TODO supply a title</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<div>TODO write content</div>
</body>
</html>

What I have tried:

It says some error with init() block but in the code it looks fine.
Posted
Updated 20-Jan-22 9:05am
Comments
Richard MacCutchan 20-Jan-22 3:44am    
"t says some error with init() block"
Sorry, we cannot guess what "some error" means. Please show exact details.
Keshav 2022 20-Jan-22 3:48am    
The build is successful and the error is shown in the apache log that i have mentioned above.

1 solution

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900