简体   繁体   English

Servlet:严重:为 servlet 分配异常

[英]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.以下堆栈跟踪是我尝试访问 servlet 时得到的,它似乎从 Tomcat 管理器运行良好。

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.在 eclipse 类路径中使用的所有 jars 都在 Tomcat lib 文件夹中可用。 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. webapp 正在部署时没有任何错误日志,但是当我尝试访问一个 servlet 时,会发生此异常,并且我将其记录在 tomcat 日志中。 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.还有某些其他 webapps,它们几乎使用相同的运行良好的库。 Expecting some one can help me with this..期待有人可以帮助我。

Thanks谢谢

Finally , got my mistake.最后,得到了我的错误。 This was a problem caused by the eclipse build.这是由 eclipse 构建引起的问题。 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.感谢您的回复。

After looking into the Exceptions, you got, some where you have misplaced the jar files在查看异常之后,您发现有些地方放错了 jar 文件

(servlet-api.jar). (servlet-api.jar)。 It should be under your Project/WEB-INF/lib folder.它应该在您的 Project/WEB-INF/lib 文件夹下。 I think it will我认为它会

works if your jar files are in the path specified above.如果您的 jar 文件位于上面指定的路径中,则工作正常。

Somehow you are missing the servlet-api.jar .不知何故,您缺少servlet-api.jar It should be located in the tomcat\\lib folder.它应该位于tomcat\\lib文件夹中。

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.如果您收到此错误“严重:为 servlet 分配异常”以及“java.lang.InstantiationException”异常,请确保您的 servlet 类具有公共无参数构造函数,因为 servlet 容器需要能够实例化它。

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.如果您的 servlet 类没有定义明确的非零参数构造函数(通常是这种情况),编译器提供的默认构造函数就足够了。

I had the same problem!我有同样的问题! Spent 2 hours searching for solution!花了2个小时寻找解决方案! 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. WebContent(在动态 Web 项目下)-> WEB-INF -> lib(它是空的-没关系)-> 右键单击​​它(lib)-> 构建路径-> 用作源文件夹。

DONE!完毕!

" java.lang.Error: Unresolved compilation problems : " 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.请将servlet-api.jar放在 classpath 中,不仅在项目的 lib 文件夹中,还要将其附加到 classpath 中。

Please make sure that same jar also available in tomcat/common/lib folder.请确保在tomcat/common/lib文件夹中也有相同的 jar。

我的案例是使用Java 8 lamda 表达式和不基于 Java 8 的旧版本 Rest

我还看到了这个异常,其中 @Resource 注释与两种技术(tomcat servlet api 3 和 spring)发生冲突。

For me, it happened when I was using Lambda expression inside my junit tests.对我来说,它发生在我在 junit 测试中使用 Lambda 表达式时。 After commenting from the tests, the server returned the proper api response.从测试中发表评论后,服务器返回了正确的 api 响应。

I got the similar exception我得到了类似的例外
While moving from java 8 to java 11 I got the following error从 java 8 迁移到 java 11 时,出现以下错误

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

To fix the error i upgraded the version in pom为了修复错误,我升级了 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我的 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>

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.转到项目属性 -> 部署程序集 -> 检查 Maven 依赖项是否可见,如果它们丢失,我们也会得到相同的错误。 I could resolve my adding the maven dependency into the Deployment Assembly.我可以解决将 maven 依赖项添加到部署程序集的问题。

[After adding Maven dependency into the Deployment Assembly, it seems like this] 【在Deployment Assembly中加入Maven依赖后,看起来是这样的】

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

I had two classes/services annotated with same path values ( javax.ws.rs.Path ).我有两个用相同路径值( javax.ws.rs.Path )注释的类/服务。 When REST API was trying to init itself there was a hard to instantly see error about duplicated paths.当 REST API 尝试自行初始化时,很难立即看到有关重复路径的错误。

I got this error while running tomcat through eclipse.我在通过 eclipse 运行 tomcat 时遇到此错误。 It was working fine and then all of a sudden it got this error after I made a few changes to javascript files.它工作正常,然后在我对 javascript 文件进行一些更改后突然出现此错误。 I have no clue why this happened, but when I closed eclipse and reopened it, it started working fine again.我不知道为什么会这样,但是当我关闭 eclipse 并重新打开它时,它又开始正常工作了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 严重:为servlet myServletName分配异常 - SEVERE: Allocate exception for servlet myServletName vaadin初学者-严重:为servlet错误分配异常 - vaadin beginner- getting SEVERE: Allocate exception for servlet error 严重:为servlet分配异常,尝试从JSP页面调用servlet时出错 - SEVERE: Allocate exception for servlet, error when trying to call a servlet from JSP page 严重:为 servlet [dispatcher] org.springframework.beans.factory.NoSuchBeanDefinitionException 分配异常: - SEVERE: Allocate exception for servlet [dispatcher] org.springframework.beans.factory.NoSuchBeanDefinitionException: 严重:为maven-webapp项目上的servlet [mvc-spring]错误分配异常 - SEVERE: Allocate exception for servlet [mvc-spring] error on maven-webapp project 为Servlet分配异常-JAVA中的Web编程 - Allocate exception for servlet - Web Programming in JAVA 为servlet Jersey REST服务错误分配异常 - Allocate exception for servlet Jersey REST Service Error TomEE:为servlet球衣-serlvet分配异常 - TomEE : Allocate exception for servlet jersey-serlvet 严重:Web应用程序中的Servlet [spring]引发load()异常 - SEVERE: Servlet [spring] in web application threw load() exception Struts 2:SEVERE:Servlet默认的Servlet.service()抛出异常java.lang.NullPointerException - Struts 2: SEVERE: Servlet.service() for servlet default threw exception java.lang.NullPointerException
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM