Servlet的debug

(1)Eclipse里面创建一个动态网页工程

(2)创建继承Servlet的class,例如com.leyuan.examples包下的HelloServlet,例如:


package com.leyuan.examples;


import java.io.IOException;


import javax.servlet.Servlet;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;


public class HelloServlet implements Servlet {


@Override
public void destroy() {
// TODO Auto-generated method stub

}


@Override
public ServletConfig getServletConfig() {
// TODO Auto-generated method stub
return null;
}


@Override
public String getServletInfo() {
// TODO Auto-generated method stub
return null;
}


@Override
public void init(ServletConfig arg0) throws ServletException {
// TODO Auto-generated method stub

}


@Override
public void service(ServletRequest arg0, ServletResponse arg1) throws ServletException, IOException {
// TODO Auto-generated method stub
System.out.println("Hello world! from YDF");
}


}

(3)Build project

(4)点击需要debug的断点

(5)在需要debug的HelloServlet.java,点击右键,选择Debug on Server

(6)在Eclipse的浏览器中输入对应的URL

(7)运行对应的URL后,进入具体的断点处

不要忘记在web.xml文件中配置servlet map,例如:

 <servlet>
        <servlet-name>HelloWorld</servlet-name>
        <servlet-class>com.leyuan.examples.HelloServlet</servlet-class>
    </servlet>
    <servlet-mapping>
        <servlet-name>HelloWorld</servlet-name>
        <url-pattern>/HelloWorld</url-pattern>
    </servlet-mapping>


你可能感兴趣的:(Servlet的debug)