来自Tomcat的HTTP状态404错误

时间:2015-04-22 16:52:15

标签: java apache tomcat servlets

我是servlet的新手,我正在测试我的第一个servlet程序但是它给出了HTTP STATUS 404错误。我所做的事情是:

1>安装java-> C:\ Program Files \ Java \ jdk1.6.0

2 - ;安装Tomcat-> C:\ Apache的Tomcat的7.0

3>当我输入 - > localhost:8080在浏览器中工作正常。

4>我创建的文件夹的目录 - > C:\ Apache的Tomcat的7.0.23 \ web应用\实例

它包含一个web.xml文件和WEB-INF文件夹。

在WEB-INF中,有一个名为classes的文件夹,其中包含validate.class

我的java文件'validate.java'的Souce代码如下 -

import javax.servlet.http.*;
import javax.servlet.*;
import java.io.*;
import java.lang.*;
public class validate extends HttpServlet{
public void service(HttpServletRequest req,HttpServletResponse res) throws ServletException,IOException{
    String name=req.getParameter("tb");
    String pass=req.getParameter("pass");
    String name1=getInitParameter("usrnme1");
    String pass1=getInitParameter("pswrd1");
    Cookie c1=new Cookie(name1,pass1);
    res.addCookie(c1);
    String name2=getInitParameter("usrnme2");
    String pass2=getInitParameter("pswrd2");
    Cookie c2=new Cookie(name2,pass2);
    res.addCookie(c2);
    String name3=getInitParameter("usrnme3");
    String pass3=getInitParameter("pswrd3");
    Cookie c3=new Cookie(name3,pass3);
    res.addCookie(c3);
    String name4=getInitParameter("usrnme4");
    String pass4=getInitParameter("pswrd4");
    Cookie c4=new Cookie(name4,pass4);
    res.addCookie(c4);
    res.setContentType("text/html");
    PrintWriter out=res.getWriter();
    Cookie[] c=req.getCookies();
    if(c!=null)
    {
        for(int i=0;i<c.length;i++)
        {
            if(c[i].getName()==name && c[i].getValue()==pass)
            {
                out.println("<html><body><center>");
                out.println("Hello"+"<b>c[i].getName()</b>");
                out.println("</center></body></html>");
                break;
            }
            else
            {
                out.println("<html><body><center>");
                out.println("Not a Valid USER");
                out.println("</center></body></html>");
                break;
            }
        }
    }
}
}

web.xml文件代码 -

<?xml version="1.0"?>
<web-app>
<servlet>
    <servlet-name>validate</servlet-name>
    <servlet-class>validate</servlet-class>
</servlet>
<init-param>
    <param-name>usrnme1</param-name>
    <param-value>user1</param-value>
</init-param>
<init-param>
    <param-name>pswrd1</param-name>
    <param-value>pwd1</param-value>
</init-param>
<init-param>
    <param-name>usrnme2</param-name>
    <param-value>user2</param-value>
</init-param>
<init-param>
    <param-name>pswrd2</param-name>
    <param-value>pwd2</param-value>
</init-param>
<init-param>
    <param-name>usrnme3</param-name>
    <param-value>user3</param-value>
</init-param>
<init-param>
    <param-name>pswrd3</param-name>
    <param-value>pwd3</param-value>
</init-param>
<init-param>
    <param-name>usrnme4</param-name>
    <param-value>user4</param-value>
</init-param>
<init-param>
    <param-name>pswrd4</param-name>
    <param-value>pwds4</param-value>
</init-param>
<servlet-mapping>
    <servlet-name>validate></servlet-name>
    <url-pattern>/validate</url-pattern>
</servlet-mapping>
</web-app>

在阅读了一些建议后,我尝试将url更改为/validate.htm(或.html),但仍然收到相同的错误消息。

HTTP Status 404 - /examples/validate.html

type Status report

message /examples/validate.html

description The requested resource (/examples/validate.html) is not available.

Apache Tomcat/7.0.27
******************************************************
Log file catalina.2015-04-22 is- 

Apr 22, 2015 9:08:18 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 (x86)\Apache Software Foundation\Tomcat 

7.0\bin;.;C:\Windows\Sun\Java\bin;C:\Windows\system32;C:\Windows;C:\ProgramData\

Oracle\Java\javapath;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\

Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files 

(x86)\Java\jdk1.8.0_31\bin;C:\Program Files 

(x86)\Java\jre1.8.0_31\bin;C:\TurboC++\Disk\TurboC3\BIN;C:\Program Files 

(x86)\Skype\Phone\;C:\Program Files (x86)\Java\jdk1.6.0_25\bin;C:\Program Files 

(x86)\Java\jre6\bin;C:\Program Files (x86)\Apache Software Foundation\Tomcat 

7.0\lib;

Apr 22, 2015 9:08:18 PM org.apache.coyote.AbstractProtocol init

INFO: Initializing ProtocolHandler ["http-bio-8080"]

Apr 22, 2015 9:08:18 PM org.apache.coyote.AbstractProtocol init

INFO: Initializing ProtocolHandler ["ajp-bio-8009"]

Apr 22, 2015 9:08:18 PM org.apache.catalina.startup.Catalina load

INFO: Initialization processed in 495 ms

Apr 22, 2015 9:08:19 PM org.apache.catalina.core.StandardService startInternal

INFO: Starting service Catalina

Apr 22, 2015 9:08:19 PM org.apache.catalina.core.StandardEngine startInternal

INFO: Starting Servlet Engine: Apache Tomcat/7.0.27

Apr 22, 2015 9:08:19 PM org.apache.catalina.startup.HostConfig deployDirectory

INFO: Deploying web application directory C:\Program Files (x86)\Apache Software Foundation\Tomcat 7.0\webapps\docs

Apr 22, 2015 9:08:19 PM org.apache.catalina.startup.HostConfig deployDirectory

INFO: Deploying web application directory C:\Program Files (x86)\Apache Software Foundation\Tomcat 7.0\webapps\examples

Apr 22, 2015 9:08:19 PM org.apache.catalina.startup.HostConfig deployDirectory

INFO: Deploying web application directory C:\Program Files (x86)\Apache Software Foundation\Tomcat 7.0\webapps\host-manager

Apr 22, 2015 9:08:19 PM org.apache.catalina.startup.HostConfig deployDirectory

INFO: Deploying web application directory C:\Program Files (x86)\Apache Software Foundation\Tomcat 7.0\webapps\manager

Apr 22, 2015 9:08:19 PM org.apache.catalina.startup.HostConfig deployDirectory

INFO: Deploying web application directory C:\Program Files (x86)\Apache Software Foundation\Tomcat 7.0\webapps\ROOT

Apr 22, 2015 9:08:19 PM org.apache.coyote.AbstractProtocol start

INFO: Starting ProtocolHandler ["http-bio-8080"]

Apr 22, 2015 9:08:19 PM org.apache.coyote.AbstractProtocol start

INFO: Starting ProtocolHandler ["ajp-bio-8009"]

Apr 22, 2015 9:08:19 PM org.apache.catalina.startup.Catalina start

INFO: Server startup in 785 ms

Apr 22, 2015 9:12:20 PM org.apache.catalina.startup.HostConfig checkResources

INFO: Reloading context [/examples]

Apr 22, 2015 9:12:24 PM org.apache.catalina.startup.HostConfig checkResources

WARNING: Error during context [/examples] restart

org.apache.catalina.LifecycleException: Failed to start component 

[StandardEngine[Catalina].StandardHost[localhost].StandardContext[/examples]]

    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:154)

    at 

org.apache.catalina.startup.HostConfig.checkResources(HostConfig.java:1366)

    at org.apache.catalina.startup.HostConfig.check(HostConfig.java:1454)

    at 

org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:295)

    at 

org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:119)

    at 

org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:90)

    at 

org.apache.catalina.core.ContainerBase.backgroundProcess(ContainerBase.java:1379)

    at 

org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChild

ren(ContainerBase.java:1537)

    at 

org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChild

ren(ContainerBase.java:1547)

    at 

org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.run(Containe

rBase.java:1526)

    at java.lang.Thread.run(Unknown Source)

Caused by: java.lang.IllegalArgumentException: Servlet mapping specifies an 

unknown servlet name hai>

    at 

org.apache.catalina.core.StandardContext.addServletMapping(StandardContext.java:

3204)

    at 

org.apache.catalina.core.StandardContext.addServletMapping(StandardContext.java:

3183)

    at org.apache.catalina.deploy.WebXml.configureContext(WebXml.java:1302)

    at 

org.apache.catalina.startup.ContextConfig.webConfig(ContextConfig.java:1294)

    at 

org.apache.catalina.startup.ContextConfig.configureStart(ContextConfig.java:855)

    at 

org.apache.catalina.startup.ContextConfig.lifecycleEvent(ContextConfig.java:345)

    at 

org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.ja

va:119)

    at 

org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:90)

    at 

org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5161

)

    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)

    ... 10 more

Apr 22, 2015 9:37:00 PM org.apache.catalina.startup.HostConfig checkResources

INFO: Reloading context [/examples]
Apr 22, 2015 9:37:04 PM org.apache.catalina.startup.HostConfig checkResources

WARNING: Error during context [/examples] restart
org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/examples]]
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:154)
    at org.apache.catalina.startup.HostConfig.checkResources(HostConfig.java:1366)
    at org.apache.catalina.startup.HostConfig.check(HostConfig.java:1454)
    at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:295)
    at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:119)
    at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:90)
    at org.apache.catalina.core.ContainerBase.backgroundProcess(ContainerBase.java:1379)
    at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1537)
    at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1547)
    at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.run(ContainerBase.java:1526)
    at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.IllegalArgumentException: Servlet mapping specifies an unknown servlet name validate>
    at org.apache.catalina.core.StandardContext.addServletMapping(StandardContext.java:3204)
    at     org.apache.catalina.core.StandardContext.addServletMapping(StandardContext.java:    3183)
    at org.apache.catalina.deploy.WebXml.configureContext(WebXml.java:1302)
    at     org.apache.catalina.startup.ContextConfig.webConfig(ContextConfig.java:1294)
    at     org.apache.catalina.startup.ContextConfig.configureStart(ContextConfig.java:855)
    at     org.apache.catalina.startup.ContextConfig.lifecycleEvent(ContextConfig.java:345)

    at     org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:119)

    at     org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:90)

    at    org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5161)

    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
    ... 10 more

请尽快帮助我。我非常感谢你。

0 个答案:

没有答案