3

我不知道这个简单的 Java Servlet 有什么问题。

Eclipse 已经生成了 Servlet..

有什么问题?

我有这个日志:

Jul 15, 2013 7:34:16 PM org.apache.catalina.core.AprLifecycleListener init
INFO: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: .:/Library/Java/Extensions:/System/Library/Java/Extensions:/usr/lib/java
Jul 15, 2013 7:34:16 PM org.apache.tomcat.util.digester.SetPropertiesRule begin
WARNING: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.jee.server:servlet' did not find a matching property.
Jul 15, 2013 7:34:17 PM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["http-bio-8080"]
Jul 15, 2013 7:34:17 PM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["ajp-bio-8009"]
Jul 15, 2013 7:34:17 PM org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 697 ms
Jul 15, 2013 7:34:17 PM org.apache.catalina.core.StandardService startInternal
INFO: Starting service Catalina
Jul 15, 2013 7:34:17 PM org.apache.catalina.core.StandardEngine startInternal
INFO: Starting Servlet Engine: Apache Tomcat/7.0.40
Jul 15, 2013 7:34:17 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["http-bio-8080"]
Jul 15, 2013 7:34:17 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["ajp-bio-8009"]
Jul 15, 2013 7:34:17 PM org.apache.catalina.startup.Catalina start
INFO: Server startup in 379 ms
Jul 15, 2013 7:34:18 PM org.apache.catalina.core.ApplicationContext log
INFO: Marking servlet TicketServlet as unavailable
Jul 15, 2013 7:34:18 PM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Allocate exception for servlet TicketServlet
java.lang.ClassNotFoundException: source.TicketServlet
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1714)
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1559)
    at org.apache.catalina.core.DefaultInstanceManager.loadClass(DefaultInstanceManager.java:527)
    at org.apache.catalina.core.DefaultInstanceManager.loadClassMaybePrivileged(DefaultInstanceManager.java:509)
    at org.apache.catalina.core.DefaultInstanceManager.newInstance(DefaultInstanceManager.java:137)
    at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1144)
    at org.apache.catalina.core.StandardWrapper.allocate(StandardWrapper.java:865)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:136)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1008)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
    at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310)
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:895)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:918)
    at java.lang.Thread.run(Thread.java:680)

文件夹结构:

servlet
  -- src
    --source
      --TicketServlet.java
  --WebContent
    --WEB-INF
      --web.xml

生成的 web.xml

<?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">
  <display-name>servlet</display-name>
  <welcome-file-list>
    <welcome-file>index.html</welcome-file>
    <welcome-file>index.htm</welcome-file>
    <welcome-file>index.jsp</welcome-file>
    <welcome-file>default.html</welcome-file>
    <welcome-file>default.htm</welcome-file>
    <welcome-file>default.jsp</welcome-file>
  </welcome-file-list>
  <servlet>
    <description></description>
    <display-name>TicketServlet</display-name>
    <servlet-name>TicketServlet</servlet-name>
    <servlet-class>source.TicketServlet</servlet-class>
  </servlet>
  <servlet-mapping>
    <servlet-name>TicketServlet</servlet-name>
    <url-pattern>/TicketServlet</url-pattern>
  </servlet-mapping>
</web-app>

票务服务程序:

package source;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class TicketServlet extends HttpServlet {
    private static final long serialVersionUID = 1L;

    protected void doGet(HttpServletRequest request, HttpServletResponse response) {

    }
}
4

2 回答 2

2

您需要从应用程序服务器添加运行时库。

例如:

转到项目属性。单击构建路径,然后单击库选项卡。单击添加库,然后选择服务器运行时。选择您的服务器,然后单击确定。

于 2014-03-10T05:21:36.440 回答
1

首先,您使用的是哪种项目???任何项目都会有一个 Java 构建路径集。要达到它..

转到项目并右键单击它并选择属性。例如XYZ项目--->右键--->属性

在选择Java 构建路径下并选择选项卡。在窗口下您可以找到路径说明符“默认输出文件夹”,它应该包含构建文件夹的路径,如图所示。

项目的属性窗口

如果它不包含路径,则可以浏览并选择构建文件夹的路径。

请记住,您的所有 servlet 类都应该在此处并且需要对其进行配置。

希望它有所帮助。如果您需要更多帮助,请随时发表评论。

于 2013-07-16T12:56:29.443 回答