使用Servlet时如何纠正以下错误? [英] How to rectify the following error while using Servlet?

查看:75
本文介绍了使用Servlet时如何纠正以下错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在学习Servlets概念.最初,我教程引用了此链接并研究HelloWorld示例.

I am learning Servlets concept. Initially, I Tutorial referred to this link and working on the HelloWorld example.

提交带有名称和年龄的JSP表单时,出现以下错误.请就必须做什么提供建议.

On submission of the JSP form with the name and age I get the following errors. Kindly advise on what has to be done.

我放置的文件的位置如下,

The locations of my files placed are as follows,

C:\ Program Files \ Apache Software Foundation \ Tomcat 5.5 \ webapps \ servletexmple \ hello.jsp

C:\Program Files\Apache Software Foundation\Tomcat 5.5\webapps\servletexmple\hello.jsp

C:\ Program Files \ Apache Software Foundation \ Tomcat5.5 \ webapps \ servletexmple \ example \ HelloServlet.class

C:\Program Files\Apache Software Foundation\Tomcat5.5\webapps\servletexmple\example\HelloServlet.class

C:\ Program Files \ Apache Software Foundation \ Tomcat 5.5 \ webapps \ servletexmple \ WEB-INF \ web.xml

C:\Program Files\Apache Software Foundation\Tomcat 5.5\webapps\servletexmple\WEB-INF\web.xml

Exception:

javax.servlet.ServletException: Wrapper cannot find servlet class example.HelloServlet or a class it depends on
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:151)
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:870)
org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:665)
org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:528)
org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:81)
org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:685)
java.lang.Thread.run(Unknown Source)

Root Cause:
java.lang.ClassNotFoundException: example.HelloServlet
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1359)
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1205)
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:151)
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:870)
org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:665)
org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:528)
org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:81)
org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:685)
java.lang.Thread.run(Unknown Source)

我的web.xml文件包含以下内容,

My web.xml file contains as follows,

<?xml version="1.0" encoding="UTF-8"?>
<web-app 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee" 
xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" 
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
id="WebApp_ID" version="2.5">

<servlet>
    <servlet-name>HelloServlet</servlet-name>
    <servlet-class>example.HelloServlet</servlet-class>
</servlet>
<servlet-mapping>
    <servlet-name>HelloServlet</servlet-name>
    <url-pattern>/servletexmple</url-pattern>
</servlet-mapping>
</web-app>

推荐答案

您必须将类文件放在webapps/servletexmple/WEB-INF/classes中.在那里,您应该遵循程序包的结构. IE.将该文件放在

You must put your class files in webapps/servletexmple/WEB-INF/classes. There you should follow the package structure. I.e. place the file in

webapp/servletexample/WEB-INF/classes/example/HelloServlet

webapp/servletexample/WEB-INF/classes/example/HelloServlet

在您的web.xml中,您应该使用Servlet的完全限定名称. IE. example.HelloServlet.有关Java程序包的更多信息,请参见此处

in your web.xml you should use the exact fully qualified name of the servlet. I.e. example.HelloServlet. For more info about packages in Java see here

这篇关于使用Servlet时如何纠正以下错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆