13

The following stacktrace is what I get when i try to access a servlet, which seems running fine from Tomcat manager.

11 Sep, 2012 11:50:12 AM org.apache.catalina.core.ApplicationContext log
INFO: Marking servlet LoginServlet as unavailable
11 Sep, 2012 11:50:12 AM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Allocate exception for servlet LoginServlet
java.lang.Error: Unresolved compilation problems: 
    The import javax.servlet cannot be resolved
    The import javax.servlet cannot be resolved
    The import javax.servlet cannot be resolved
    The import javax.servlet cannot be resolved
    The import javax.servlet cannot be resolved
    The import javax.servlet cannot be resolved
    HttpServlet cannot be resolved to a type
    ServletConfig cannot be resolved to a type
    ServletException cannot be resolved to a type
    HttpServlet cannot be resolved to a type
    ServletContext cannot be resolved to a type
    ServletException cannot be resolved to a type
    HttpServletRequest cannot be resolved to a type
    HttpServletResponse cannot be resolved to a type
    ServletException cannot be resolved to a type
    request cannot be resolved
    The method getLoggedin() from the type LoginHandler refers to the missing type ServletException
    The method destroy() of type LoginManager must override or implement a supertype method
    HttpServlet cannot be resolved to a type

    at com.login.servlets.LoginManager.<init>(LoginManager.java:5)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
    at java.lang.reflect.Constructor.newInstance(Unknown Source)
    at java.lang.Class.newInstance0(Unknown Source)
    at java.lang.Class.newInstance(Unknown Source)
    at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1149)
    at org.apache.catalina.core.StandardWrapper.allocate(StandardWrapper.java:827)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:129)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
    at org.apache.coyote.http11.Http11AprProcessor.process(Http11AprProcessor.java:877)
    at org.apache.coyote.http11.Http11AprProtocol$Http11ConnectionHandler.process(Http11AprProtocol.java:594)
    at org.apache.tomcat.util.net.AprEndpoint$Worker.run(AprEndpoint.java:1675)
    at java.lang.Thread.run(Unknown Source)
11 Sep, 2012 12:05:12 PM org.apache.catalina.core.ApplicationContext log
INFO: Marking servlet Log4JInitServlet as unavailable
11 Sep, 2012 12:05:12 PM org.apache.catalina.core.StandardContext loadOnStartup
SEVERE: Servlet /logintest threw load() exception
java.lang.Error: Unresolved compilation problems: 
    The import javax.servlet cannot be resolved
    The import javax.servlet cannot be resolved
    The import javax.servlet cannot be resolved
    The import javax.servlet cannot be resolved
    The import org.apache cannot be resolved
    The import org.apache cannot be resolved
    HttpServlet cannot be resolved to a type
    ServletConfig cannot be resolved to a type
    ServletException cannot be resolved to a type
    ServletContext cannot be resolved to a type
    BasicConfigurator cannot be resolved
    PropertyConfigurator cannot be resolved
    BasicConfigurator cannot be resolved

    at com.logger.WebLogger.<init>(WebLogger.java:5)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
    at java.lang.reflect.Constructor.newInstance(Unknown Source)
    at java.lang.Class.newInstance0(Unknown Source)
    at java.lang.Class.newInstance(Unknown Source)
    at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1149)
    at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1026)
    at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:4421)
    at org.apache.catalina.core.StandardContext.start(StandardContext.java:4734)
    at org.apache.catalina.core.StandardContext.reload(StandardContext.java:3461)
    at org.apache.catalina.manager.ManagerServlet.reload(ManagerServlet.java:943)
    at org.apache.catalina.manager.HTMLManagerServlet.reload(HTMLManagerServlet.java:557)
    at org.apache.catalina.manager.HTMLManagerServlet.doGet(HTMLManagerServlet.java:121)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.apache.catalina.filters.CsrfPreventionFilter.doFilter(CsrfPreventionFilter.java:186)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:563)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
    at org.apache.coyote.http11.Http11AprProcessor.process(Http11AprProcessor.java:877)
    at org.apache.coyote.http11.Http11AprProtocol$Http11ConnectionHandler.process(Http11AprProtocol.java:594)
    at org.apache.tomcat.util.net.AprEndpoint$Worker.run(AprEndpoint.java:1675)
    at java.lang.Thread.run(Unknown Source)

All the jars which was used inside eclipse classpath is avaiable in Tomcat lib folder. The webapp is getting deployed with out any error logs, but when i try to access one servlet, this exception occurs, and i get it logged in the tomcat logs. Can any one help with this?

The package names are proper inside 'classes', also, the web.xml is proper. 

I dont know then why this happens. There are certain other webapps, which almost uses the same libs running fine. Expecting some one can help me with this..

Thanks

Kris
  • 8,680
  • 4
  • 39
  • 67

14 Answers14

16

Finally , got my mistake. This was a problem caused by the eclipse build. Since the build was not proper, the class files where corrupted. I cleaned up the whole project, took a fresh build, now its working fine. Thanks for your replies.

Kris
  • 8,680
  • 4
  • 39
  • 67
4

Somehow you are missing the servlet-api.jar. It should be located in the tomcat\lib folder.

Tarlog
  • 10,024
  • 2
  • 43
  • 67
4

After looking into the Exceptions, you got, some where you have misplaced the jar files

(servlet-api.jar). It should be under your Project/WEB-INF/lib folder. I think it will

works if your jar files are in the path specified above.

Srinivas B
  • 1,821
  • 4
  • 17
  • 35
4

I had the same problem! Spent 2 hours searching for solution! And here it is!

WebContent (under Dynamic Web Project) -> WEB-INF -> lib (it's empty- all right) -> right click on it (lib) -> Build Path -> Use as Source Folder.

DONE!

Vitali
  • 549
  • 6
  • 16
2

If you get this error "SEVERE: Allocate exception for servlet" coupled with a "java.lang.InstantiationException" exception, make sure that your servlet class has a public no-argument constructor since the servlet container needs to be able to instantiate it.

If your servlet class does not have an explicit non-zero argument constructor defined (which is usually the case), the default constructor provided by the compiler would suffice.

ushah
  • 21
  • 1
2

My case was using Java 8 lamda expressions with older version of Rest that was not based on Java 8

Youans
  • 4,801
  • 1
  • 31
  • 57
1

"java.lang.Error: Unresolved compilation problems: "

says that application is not compiled properly. Please put the servlet-api.jar in classpath, not just in lib folder of project, but also attach that to classpath.

Please make sure that same jar also available in tomcat/common/lib folder.

Hardik Mishra
  • 14,779
  • 9
  • 61
  • 96
Ratnakar.class
  • 301
  • 5
  • 12
0

I also saw this exception where the @Resource annotation caused a conflict with two technologies stepping on each other's toes (tomcat servlet api 3, and spring).

Kimball Robinson
  • 3,287
  • 9
  • 47
  • 59
0

For me, it happened when I was using Lambda expression inside my junit tests. After commenting from the tests, the server returned the proper api response.

Yash Bansal
  • 402
  • 5
  • 10
0

I got the similar exception
While moving from java 8 to java 11 I got the following error

Exception org.apache.catalina.core.ApplicationContext.log Servlet.init() for servlet [health-servlet] threw exception java.lang.IllegalArgumentException

To fix the error i upgraded the version in pom

<jersey.version>2.23.2</jersey.version><!-- Remove this  -->
<jersey.version>2.30.1</jersey.version><!-- Add this  -->

I had the following entry in my web.xml

    <servlet>
    <servlet-name>health-servlet</servlet-name>
    <servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
    <init-param>
        <param-name>javax.ws.rs.Application</param-name>
        <param-value>com.xyz.platform.registry.service.ServiceRegistryApplication</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
</servlet>
user1889970
  • 726
  • 1
  • 8
  • 12
0

Go to the Project Properties -> Deployment Assembly -> Check whether the maven dependencies are visible, if they are missing the also we get the same error. I could resolve my adding the maven dependency into the Deployment Assembly.

[After adding Maven dependency into the Deployment Assembly, it seems like this]

https://i.stack.imgur.com/7iwaW.jpg

0

I had two classes/services annotated with same path values (javax.ws.rs.Path). When REST API was trying to init itself there was a hard to instantly see error about duplicated paths.

user435421
  • 859
  • 2
  • 13
  • 31
0

I got this error while running tomcat through eclipse. It was working fine and then all of a sudden it got this error after I made a few changes to javascript files. I have no clue why this happened, but when I closed eclipse and reopened it, it started working fine again.

jonesy19
  • 139
  • 1
  • 16
0

I got this error while the servlet is defined in web.xml but the servlet class not exist. after check the servlet class, and the servlet class name in web.xml be full class name with package prefix, the servlet return page reponse.

yu yang Jian
  • 6,680
  • 7
  • 55
  • 80