【问题标题】:TOMCAT status 404 tried it all errorTOMCAT 状态 404 尝试了所有错误
【发布时间】:2014-01-26 09:02:49
【问题描述】:

我正在尝试在 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

类:

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>

【问题讨论】:

  • 您正在部署任何应用程序?如果您部署任何应用程序发布应用程序的web.xml
  • 是的,刚刚添加了 web.xml.. 假设在屏幕上显示用户名和密码条目。在 WebContent 中也有一个 .html 文件
  • Example03 文件夹中有文件 default.* 或 index.* 吗?
  • 不,没有。在文件夹中也找不到任何东西..
  • 您的日志根本没有显示正在部署的应用程序。你是如何部署它的?

标签: java apache http tomcat http-status-code-404


【解决方案1】:

从您的 cmets 来看,我建议您从头开始使用 tomcat。看看这个link

只是简单概述一下 tomcat 的工作原理

  1. official website下载tomcat(下载的一个eclipse也可以正常工作,但是这样你就可以了解tomcat的来龙去脉了
  2. 解压到你有读/写权限的目录
  3. 对于测试运行,转到 $Tomcat_Dir$/bin 并执行 startup.shstartup.bat(对于基于 Windows 的系统)
  4. 在浏览器中localhost:8080应该给你tomcat的默认页面
  5. 接下来,将您的应用程序打包为一个战争(例如 myApp.war)
  6. 将此myApp.war 放入$Tomcat_Dir$/webapps 文件夹并重新启动tomcat。您将看到在 webapps 文件夹中创建了一个与 war 同名的文件夹
  7. 现在http://localhost:8080/myApp 将打开您的应用程序的默认页面(如果您已配置它)。否则,根据您的 web.xml,localhost:8080/myApp/servlet1 将触发 servlet

【讨论】:

  • 呵呵,是的,没有问题.. 最后一个问题.. 我是否需要同时下载核心和部署程序才能运行 Web 应用程序?
  • 你只需要Core 就可以了
猜你喜欢
  • 2021-06-19
  • 2018-10-31
  • 1970-01-01
  • 2014-09-11
  • 2017-03-28
  • 2023-03-04
  • 1970-01-01
  • 2019-04-11
  • 2012-04-22
相关资源
最近更新 更多