url-pattern 是你的url访问时的路径,比如
http://localhost/ksm01/WebRoot/Login而 servlet-class 就是访问这个url时,调用的servlet

解决方案 »

  1.   

    url-pattern是访问servlet的方式 模式
    它和servlet-class两者通过servlet-name为媒彼此呼应
    三者都是围绕一个中心(servlet)转
      

  2.   

    再问一下就是这个class--cn.mldn.lxh.note.servlet.LoginServlet是不是因该在x:\ksm01\WebRoot\WEB-INF\classes\cn\mldn\lxh\note\servlet目录下?
      

  3.   

    正确,
    子目录和package相同
      

  4.   

    是的,编译好的.class文件是放在那个目录下
      

  5.   

    还有就是我的服务器是tomcat的,在启动后访问这个http://localhost:8080/ex/ksm01/WebRoot/Login出现404错误有可能是什么原因呢?
    server.xml中已经加入了<Context path="/ex" docBase="D:\example" />
    LoginServlet class文件也在相应的文件夹下面
      

  6.   

    你的 docBase明明在
    x:\ksm01\WebRoot
    怎么又变成了 d:\example 了???
      

  7.   

    不好意思哈,我重新用myeclipse做的所以变成了d:\example\ksm01\WebRoot
      

  8.   

    LoginServlet.java的内容是:(是 照着别人的例子作的 )
    package cn.mldn.lxh.note.servlet ;import java.io.* ;
    import javax.servlet.* ;
    import javax.servlet.http.* ;
    import cn.mldn.lxh.note.vo.* ;
    import cn.mldn.lxh.note.factory.* ;public class LoginServlet extends HttpServlet
    {
    public void doGet(HttpServletRequest request,HttpServletResponse response) throws IOException,ServletException
    {
    this.doPost(request,response) ;
    }
    public void doPost(HttpServletRequest request,HttpServletResponse response) throws IOException,ServletException
    {
    String path = "login.jsp" ;
    // 1、接收传递的参数
    String id = request.getParameter("id") ;
    String password = request.getParameter("password") ;
    // 2、将请求的内容赋值给VO类
    Person person = new Person() ;
    person.setId(id) ;
    person.setPassword(password) ;

    try
    {
    // 进行数据库验证
    if(DAOFactory.getPersonDAOInstance().login(person))
    {
    // 如果为真,则表示用户ID和密码合法
    // 设置用户姓名到session范围之中
    request.getSession().setAttribute("uname",person.getName()) ;
    // 修改跳转路径
    path = "login_success.jsp" ;
    }
    else
    {
    // 登陆失败
    // 设置错误信息
    request.setAttribute("err","错误的用户ID及密码!!!") ;
    }
    }
    catch(Exception e)
    {}
    // 进行跳转
    request.getRequestDispatcher(path).forward(request,response) ;
    }
    };
      

  9.   

    那你的配置应该是
    <Context path="/ex" docBase="d:\example\ksm01\WebRoot" /> 
      

  10.   

    非常感谢楼上老大
    当配置是这个的时候:<Context path="/ex" docBase="d:\example\ksm01\WebRoot" /> 
    <url-pattern>/Login </url-pattern> 能够访问
    为什么配置是这个的时候不行呢?我还是没有搞明白
    <Context path="/ex" docBase="d:\example" /> 
    <url-pattern>/ksm01/WebRoot/Login </url-pattern>
    以上两种配置访问地址不一样吗 ?