我不知道这个简单的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>
TicketServlet:
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) {
}
}
答案 0 :(得分:2)
您需要从应用程序服务器添加运行时库。
例如:
转到项目属性。单击Build Path,然后单击libraries选项卡。单击添加库,然后选择服务器运行时。选择您的服务器,然后单击“确定”。
答案 1 :(得分:1)
首先,您使用的是哪种项目?任何项目都将具有Java Build Path集。 要做到这一点..
转到Project并右键单击它并选择Properties。例如XYZ项目 ---&gt;右键单击---&gt;属性
在选择 Java构建路径下,选择来源标签。在窗口下方,您可以找到路径说明符“默认输出文件夹”,这应该包含构建文件夹的路径,如图所示。
如果它不包含路径,则可以去浏览并选择构建文件夹的路径。
请记住,所有servlet的类都应该在这里,并且需要进行配置。
希望它有帮助.. 如果您需要更多帮助,请随时发表评论。