我正在尝试在 tomcat 上运行 web.xml 文件并在其中设置服务器/服务器映射。显然,错误日志似乎没有错误(如果我没有错的话),我尝试使用 localhost:8080/Example03/servlet1 、 localhost:8080/Example03 和 localhost:8080/servlet1 正如我读到的一些文章发布了某些版本的 tomcat 上的新实现.. 只显示 http 错误 404(状态报告 - 请求的资源不可用)。使用 v6.0.. 有没有人知道我可以尝试让它工作的东西
Jan 08, 2014 5:59:48 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: C:\Program Files\Java\jre7\bin;C:\Windows\Sun\Java\bin;C:\Windows\system32;C:\Windows;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\Windows Live\Shared;.
Jan 08, 2014 5:59:48 PM org.apache.tomcat.util.digester.SetPropertiesRule begin
WARNING: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.jee.server:Example03' did not find a matching property.
Jan 08, 2014 5:59:48 PM org.apache.coyote.http11.Http11Protocol init
INFO: Initializing Coyote HTTP/1.1 on http-8080
Jan 08, 2014 5:59:48 PM org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 494 ms
Jan 08, 2014 5:59:48 PM org.apache.catalina.core.StandardService start
INFO: Starting service Catalina
Jan 08, 2014 5:59:48 PM org.apache.catalina.core.StandardEngine start
INFO: Starting Servlet Engine: Apache Tomcat/6.0.26
Jan 08, 2014 5:59:48 PM org.apache.coyote.http11.Http11Protocol start
INFO: Starting Coyote HTTP/1.1 on http-8080
Jan 08, 2014 5:59:48 PM org.apache.jk.common.ChannelSocket init
INFO: JK: ajp13 listening on /0.0.0.0:8009
Jan 08, 2014 5:59:48 PM org.apache.jk.server.JkMain start
INFO: Jk running ID=0 time=0/32 config=null
Jan 08, 2014 5:59:48 PM org.apache.catalina.startup.Catalina start
INFO: Server startup in 272 ms
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">
<servlet>
<servlet-name>Test</servlet-name>
<servlet-class>org.test.webapp.ServletExample</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Test</servlet-name>
<url-pattern>/servlet1</url-pattern>
</servlet-mapping>
<display-name>Example03</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>
</web-app>
重新登录:
Jan 08, 2014 7:25:41 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: C:\Program Files\Java\jre7\bin;C:\Windows\Sun\Java\bin;C:\Windows\system32;C:\Windows;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\Windows Live\Shared;.
Jan 08, 2014 7:25:41 PM org.apache.tomcat.util.digester.SetPropertiesRule begin
WARNING: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.jee.server:Example03' did not find a matching property.
Jan 08, 2014 7:25:41 PM org.apache.coyote.http11.Http11Protocol init
INFO: Initializing Coyote HTTP/1.1 on http-8080
Jan 08, 2014 7:25:41 PM org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 498 ms
Jan 08, 2014 7:25:41 PM org.apache.catalina.core.StandardService start
INFO: Starting service Catalina
Jan 08, 2014 7:25:41 PM org.apache.catalina.core.StandardEngine start
INFO: Starting Servlet Engine: Apache Tomcat/6.0.26
Jan 08, 2014 7:25:41 PM org.apache.catalina.startup.HostConfig deployDescriptor
INFO: Deploying configuration descriptor host-manager.xml
Jan 08, 2014 7:25:42 PM org.apache.catalina.startup.HostConfig deployDescriptor
INFO: Deploying configuration descriptor manager.xml
Jan 08, 2014 7:25:42 PM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deploying web application directory docs
Jan 08, 2014 7:25:42 PM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deploying web application directory examples
Jan 08, 2014 7:25:42 PM org.apache.catalina.core.ApplicationContext log
INFO: ContextListener: contextInitialized()
Jan 08, 2014 7:25:42 PM org.apache.catalina.core.ApplicationContext log
INFO: SessionListener: contextInitialized()
Jan 08, 2014 7:25:42 PM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deploying web application directory ROOT
Jan 08, 2014 7:25:42 PM org.apache.coyote.http11.Http11Protocol start
INFO: Starting Coyote HTTP/1.1 on http-8080
Jan 08, 2014 7:25:42 PM org.apache.jk.common.ChannelSocket init
INFO: JK: ajp13 listening on /0.0.0.0:8009
Jan 08, 2014 7:25:42 PM org.apache.jk.server.JkMain start
INFO: Jk running ID=0 time=0/23 config=null
Jan 08, 2014 7:25:42 PM org.apache.catalina.startup.Catalina start
INFO: Server startup in 646 ms
类(class):
package org.test.webapp;
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 ServletExample extends HttpServlet {
public void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException,IOException{
String name = req.getParameter("userName");
String email = req.getParameter("email");
String IP = req.getRemoteAddr();
resp.getWriter().println("<html>");
resp.getWriter().println("<head>");
resp.getWriter().println("<title>this is the response</title>");
resp.getWriter().println("</head>");
resp.getWriter().println("<body>");
resp.getWriter().println("your name is: "+ name);
resp.getWriter().println("your email is: "+ email);
resp.getWriter().println("your ip is: "+ IP);
resp.getWriter().println("</body>");
resp.getWriter().println("</html>");
}
}
WEB-INF 中的 index.html:
<html>
<head>
<title> Test Form</title>
</head>
<body>
<form action="servlet1" method="get">
Name : <input type="text" name="name"><br>
Email : <input type="text" name="email"><br>
<input type = "submit" value="submit!">
</form>
</body>
</html>
最佳答案
根据您的意见,我建议您从头开始使用 tomcat。看看这个 link .
简单介绍一下tomcat的工作原理
- 从 official website 下载 tomcat (下载的一个 eclipse 也可以正常工作,但这样你就会了解 tomcat 的来龙去脉
- 将其解压缩到您具有读/写权限的目录中
- 对于测试运行,转到
$Tomcat_Dir$/bin
并执行startup.sh
或startup.bat
(如果是基于 Windows系统) - 在浏览器中,
localhost:8080
应该给你tomcat的默认页面 - 接下来,将您的应用程序打包为 war(例如 myApp.war)
- 将此
myApp.war
放入$Tomcat_Dir$/webapps
文件夹并重新启动 tomcat。您会看到在 webapps 文件夹中创建了一个与 war 同名的文件夹 - 现在
http://localhost:8080/myApp
将打开您的应用程序的默认页面(如果您已配置它)。否则,根据您的 web.xml,localhost:8080/myApp/servlet1
将触发 servlet
关于java - TOMCAT 状态 404 试了所有错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20992659/