我试图在tomcat上运行web.xml文件并在其中设置server / server-mapping。显然错误日志似乎没有错误(如果我没有错),我尝试使用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
类:
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>
答案 0 :(得分:0)
从你的评论中,我建议你从头开始使用tomcat。请查看此link。
简要介绍一下tomcat的工作原理
$Tomcat_Dir$/bin
并执行startup.sh
或startup.bat
(如果是基于Windows的系统)localhost:8080
应该为您提供tomcat的默认页面myApp.war
放在$Tomcat_Dir$/webapps
文件夹中,然后重新启动tomcat。您将在webapps文件夹中看到一个与war http://localhost:8080/myApp
将打开应用程序的默认页面(如果已配置)。否则,根据您的web.xml,localhost:8080/myApp/servlet1
将触发servlet