Servlet的debug

本文详细介绍了如何在Eclipse中创建动态网页项目,并通过具体步骤引导读者实现一个简单的Servlet实例。从项目的创建到断点调试及最终在浏览器中运行,涵盖了整个开发流程。此外,还特别强调了web.xml配置的重要性。

(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>


@echo off :: ----------------------------------------------------------------------------- :: HD Win32 Shell Script :: :: ----------------------------------------------------------------------------- :: Configuration variables :: :: HD_HOME :: Folder that points to the root of the HD distribution :: :: HD_WEBAPP_HOME :: The root of the HD web application :: :: JAVA_HOME :: Home of Java installation. :: :: JAVA_OPTIONS :: Extra options to pass to the JVM :: :: JAVA_DEBUG_PORT :: The location where the JVM debug server should listen to :: :: :: ----- Verify and Set Required Environment Variables ------------------------- if not "%JAVA_HOME%" == "" goto gotJavaHome echo You must set JAVA_HOME to point at your Java Development Kit installation goto end :gotJavaHome :: ----- Check System Properties ----------------------------------------------- if not "%EXEC%" == "" goto gotExec if not "%OS%" == "Windows_NT" goto noExecNT set EXEC= goto gotExec :noExecNT set EXEC= :gotExec if not "%HD_HOME%" == "" goto gotHome set HD_HOME=. :gotHome if not "%HD_WEBAPP_HOME%" == "" goto gotWebapp set HD_WEBAPP_HOME=%HD_HOME%\build\webapp :gotWebapp echo hd.bat: using %HD_WEBAPP_HOME% as the webapp directory if not "%JAVA_DEBUG_PORT%" == "" goto gotDebugPort set JAVA_DEBUG_PORT=8000 :gotDebugPort if not "%JAVA_OPTIONS%" == "" goto gotJavaOptions set JAVA_OPTIONS=-Xms256M -Xmx1024M -Dfile.encoding=UTF-8 :gotJavaOptions :: ----- Set Local Variables ( used to minimize cut/paste) --------------------- set JAVA="%JAVA_HOME%\bin\java" set JAVA_CP=-cp "%HD_WEBAPP_HOME%" set LAUNCHER="org.springframework.boot.loader.WarLauncher" set JAVA_DEBUG_ARGS=-Xdebug -agentlib:jdwp=transport=dt_socket,address=%JAVA_DEBUG_PORT%,server=y,suspend=n :: ----- Check action ---------------------------------------------------------- if ""%1"" == ""run"" goto doServlet if ""%1"" == ""debug"" goto doDebug :: if ""%1"" == ""stop"" goto doShutdown echo Usage: hd (action) echo actions: echo run Run HD server echo debug Run HD server and turn on remote JVM debug goto end :: ----- Servlet --------------------------------------------------------------- :doServlet %EXEC% %JAVA% %JAVA_OPTIONS% %JAVA_CP% %LAUNCHER% goto end :: ----- Servlet Debug --------------------------------------------------------- :doDebug chcp 65001 %EXEC% %JAVA% %JAVA_OPTIONS% %JAVA_DEBUG_ARGS% %JAVA_CP% %LAUNCHER% goto end :: ----- End ------------------------------------------------------------------- :end set CP= set EXEC=
最新发布
10-21
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值