package servlettest;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class MyFirstServlet extends HttpServlet{ public void doGet(HttpServletRequest request,HttpServletResponse response) throws ServletException,IOException{
response.setContentType("text/html");
ServletOutputStream out=response.getOutputStream();
out.println("");
out.println("");
out.println("");
out.println("<h1>FirstServlet!</h1>");
out.println("");
}
}
启动tomcat部署完之后,在浏览器里没有显示(报错404)http://localhost:8080/MyFirstServlet或者http://localhost:8080/MyFirstServlet

解决方案 »

  1.   

    http://localhost:8080/项目名/MyFirstServlet
    楼主没加项目名吧
      

  2.   

    应该是地址写错了,localhost:8080/项目名称/ServletName吧。你试试
      

  3.   

    404错误就是无法发现页面,地址栏里输错了,或者你没在web.xml配置好
      

  4.   


    同时要保证servlet是标准的正确的,
      

  5.   

    你查查你的项目下有欢迎页么?就是index.html文件。
      

  6.   

    如何你是用myeclipse 开发的话,要在servers出将你的项目加进去。我以前也遇到过这样的问题
      

  7.   

    404就是请求路径无效。
    http://localhost:8080/项目名/MyFirstServlet 
    请求这个路径的时候,你要确保在xml中配置servlet的路径是否是MyFirstServlet 
      

  8.   

    配置你的web.xml  如果servlet没有mapping的话,需要用servlet的全名来作为访问地址你需要用http://localhost:8080/<your context name>/servlets/servlettest.MyFirstServlet
      

  9.   

    web.xml看看配置的请求路径对不对。
      

  10.   

    web.xml配置没有啊????
    <servlet></servlet><servlet-mapping><servlet-mapping>通过servlet-mapping同servlet对应在对应相应的处理方法就可以了
    注意请求的url必需同servlet的url-pattern对应
      

  11.   

    404,哈哈,小问题,看你的web.xml中servlet的配置路径是什么啊?