我弄一天了,老是404找不到文件,非常纳闷
把JAVA文件放servlet也404咋办
文件放在D:\apache-tomcat-7.0.2-windows-x86\apache-tomcat-7.0.2\webapps\ROOT\WEB-INF\web.xml
<?xml version="1.0" encoding="ISO-8859-1"?>
<!--
 Licensed to the Apache Software Foundation (ASF) under one or more
  contributor license agreements.  See the NOTICE file distributed with
  this work for additional information regarding copyright ownership.
  The ASF licenses this file to You under the Apache License, Version 2.0
  (the "License"); you may not use this file except in compliance with
  the License.  You may obtain a copy of the License at      http://www.apache.org/licenses/LICENSE-2.0  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.
--><web-app xmlns="http://java.sun.com/xml/ns/javaee"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
                      http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
  version="3.0"
  metadata-complete="true">    <display-name>Welcome to Tomcat</display-name>
  <description>
     Welcome to Tomcat
  </description><servlet>
<servlet-name>FirstServlet</servlet-name>
<servlet-class>com.helloweenvsfei.servlet.FirstServlet</servlet-class>
</servlet><servlet-mapping>
<servlet-name>FirstServlet</servlet-name>
<url-pattern>/servlet/FirstServlet</url-pattern>
</servlet-mapping></web-app>
文件放在D:\apache-tomcat-7.0.2-windows-x86\apache-tomcat-7.0.2\webapps\ROOT\FirstServlet.java
package com.helloweenvsfei.servlet;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class FirstServlet extends HttpServlet{
public void doGet(HttpServletRequest request,HttpServletResponse response) throws ServletException,IOException{
this.log("do doGet method");
this.execute(request,response);
}
public void doPost(HttpServletRequest request,HttpServletResponse response) throws ServletException,IOException{
this.log("do doPost method");
this.execute(request,response);
}
public long getLastModified(HttpServletRequest request){
this.log("do getLastModified method");
return -1;
}
private void execute(HttpServletRequest request,HttpServletResponse response) throws ServletException,IOException{
response.setCharacterEncoding("UTF-8");
request.setCharacterEncoding("UTF-8");
String requestURI=request.getRequestURI();
String method=request.getMethod();
String param=request.getParameter("param");
response.setContentType("text/html");
PrintWriter out=response.getWriter();
out.println("<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">");
out.println("<HTML>");
out.println("<BODY>");
out.println(method+":"+param+"<br/>");
out.println("<form action='"+requestURI+"' method='get'><input type='text' name='param' value='param string'><input type='submit' value='GET"+requestURI+"'><form>");
out.println("<form action='"+requestURI+"' method='post'><input type='text' name='param' value='param string'><input type='submit' value='POST"+requestURI+"'></form>");
out.println("<script>document.write('lastdatatime'+document.lastModified);</script>");
out.println("</BODY>");
out.println("</HTML>");
out.flush();
out.close();
}
}
我文件放在D:\apache-tomcat-7.0.2-windows-x86\apache-tomcat-7.0.2\webapps\ROOT

解决方案 »

  1.   

    servlet要编译的,  不能直接放.java
      

  2.   

    顶一楼!
    不能用java,要编译成.class并且要放在
    D:\apache-tomcat-7.0.2-windows-x86\apache-tomcat-7.0.2\webapps\ROOT\WEB-INF\com\helloweenvsfei\servlet\
    目录下。
    其中红色是java包对应的目录
      

  3.   

    目录错了,少了classes
    D:\apache-tomcat-7.0.2-windows-x86\apache-tomcat-7.0.2\webapps\ROOT\WEB-INF\classes\com\helloweenvsfei\servlet\
      

  4.   

    看看你FORM()里的action是不是/servlet/FirstServlet。
      

  5.   

    哦,原来这样,书上一点也没说放在CLASSES目录下,我建了N多个虚拟目录,弄了一天都没弄好快烦死人了,谢谢大家!