我按照此页面的教程。http://www.coreservlets.com/Apache-Tomcat-Tutorial/tomcat-7-with-eclipse.html下载了test-app zip文件。该文件工作正常。但是,当我尝试创建一个简单的helloworld Servlet时,它会产生404错误。我在论坛上也看到了相关的问题,但似乎没有人能解决这个问题。我正在使用tomcat7和java6 ee。 我能够添加链接并访问静态网页纯HTML页面,但在我尝试访问servlet时获得404。 这是我的servlet代码。
@WebServlet(name="LoginServlet1",urlPatterns={"/LoginServlet1"})
public class LoginServlet1 extends HttpServlet {
public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println
("<!DOCTYPE html>\n" +
"<html>\n" +
"<head><title>A Test Servlet</title></head>\n" +
"<body bgcolor=\"#fdf5e6\">\n" +
"<h1>Test</h1>\n" +
"<p>Simple servlet for testing.</p>\n" +
"</body></html>");
}
}
这是我的index.html
<!DOCTYPE html>
<html>
<head><title>Test Web App for Tomcat 7 or Other Servlet 3.0 Container</title>
<link rel="stylesheet"
href="./css/styles.css"
type="text/css"/>
</head>
<body>
<table class="title">
<tr><th>Test Web App for Tomcat 7</th></tr>
</table>
<p/>
<fieldset>
<ul>
<li><a href="LoginServlet1">hello</a> The HelloWorld servlet that
generates plain text.</li>
</ul>
</fieldset>
<p/>
</body></html>
这是启动时的控制台日志。
Jun 08, 2014 11:00:55 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: /usr/java/packages/lib/amd64:/usr/lib/x86_64-linux-gnu/jni:/lib/x86_64-linux-gnu:/usr/lib/x86_64-linux-gnu:/usr/lib/jni:/lib:/usr/lib
Jun 08, 2014 11:00:55 PM org.apache.tomcat.util.digester.SetPropertiesRule begin
WARNING: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.jee.server:test-app' did not find a matching property.
Jun 08, 2014 11:00:55 PM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["http-bio-8080"]
Jun 08, 2014 11:00:55 PM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["ajp-bio-8009"]
Jun 08, 2014 11:00:55 PM org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 989 ms
Jun 08, 2014 11:00:55 PM org.apache.catalina.core.StandardService startInternal
INFO: Starting service Catalina
Jun 08, 2014 11:00:55 PM org.apache.catalina.core.StandardEngine startInternal
INFO: Starting Servlet Engine: Apache Tomcat/7.0.47
Jun 08, 2014 11:00:56 PM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deploying web application directory /home/karan/tomcat eclipse/webapps/SensorWebApplication4
Jun 08, 2014 11:00:58 PM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deploying web application directory /home/karan/tomcat eclipse/webapps/examples
Jun 08, 2014 11:00:58 PM org.apache.catalina.core.ApplicationContext log
INFO: ContextListener: contextInitialized()
Jun 08, 2014 11:00:58 PM org.apache.catalina.core.ApplicationContext log
INFO: SessionListener: contextInitialized()
Jun 08, 2014 11:00:58 PM org.apache.catalina.core.ApplicationContext log
INFO: ContextListener: attributeAdded('org.apache.jasper.compiler.TldLocationsCache', 'org.apache.jasper.compiler.TldLocationsCache@6c814dbd')
Jun 08, 2014 11:00:58 PM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deploying web application directory /home/karan/tomcat eclipse/webapps/SensorWebApplication1
Jun 08, 2014 11:01:00 PM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deploying web application directory /home/karan/tomcat eclipse/webapps/SensorWebApplication9
Jun 08, 2014 11:01:01 PM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deploying web application directory /home/karan/tomcat eclipse/webapps/ROOT
Jun 08, 2014 11:01:01 PM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deploying web application directory /home/karan/tomcat eclipse/webapps/host-manager
Jun 08, 2014 11:01:01 PM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deploying web application directory /home/karan/tomcat eclipse/webapps/manager
Jun 08, 2014 11:01:01 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["http-bio-8080"]
Jun 08, 2014 11:01:01 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["ajp-bio-8009"]
Jun 08, 2014 11:01:01 PM org.apache.catalina.startup.Catalina start
INFO: Server startup in 6144 ms
答案 0 :(得分:0)
这里的一切似乎都很好。尝试删除服务器并创建一个新服务器...并运行该项目。 Tomcat确实表现得很奇怪。