Kris
Kris

Reputation: 8873

Servlet : SEVERE: Allocate exception for servlet

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

Upvotes: 13

Views: 123579

Answers (14)

yu yang Jian
yu yang Jian

Reputation: 7171

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.

Upvotes: 0

jonesy19
jonesy19

Reputation: 133

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.

Upvotes: 0

user435421
user435421

Reputation: 927

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.

Upvotes: 0

SHILPA SAI
SHILPA SAI

Reputation: 1

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.sstatic.net/7iwaW.jpg

Upvotes: 0

user1889970
user1889970

Reputation: 736

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>

Upvotes: 1

Yash Bansal
Yash Bansal

Reputation: 400

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.

Upvotes: 0

Vitali
Vitali

Reputation: 549

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!

Upvotes: 4

Youans
Youans

Reputation: 5071

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

Upvotes: 2

ushah
ushah

Reputation: 21

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.

Upvotes: 2

Kimball Robinson
Kimball Robinson

Reputation: 3388

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).

Upvotes: 0

Kris
Kris

Reputation: 8873

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.

Upvotes: 16

Srinivas B
Srinivas B

Reputation: 1852

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.

Upvotes: 4

Ratnakar.class
Ratnakar.class

Reputation: 320

"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.

Upvotes: 1

Tarlog
Tarlog

Reputation: 10154

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

Upvotes: 4

Related Questions