如何使用 Eclipse 调试 servlet

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5305744/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 15:59:34  来源:igfitidea点击:

How to debug servlet using Eclipse

javaeclipsetomcatservlets

提问by user496949

Have a servlet and it can run inside TomCat. However, I am not sure how to debug it inside Eclipse(Java Standard version). Any suggestions?

有一个 servlet,它可以在 TomCat 中运行。但是,我不确定如何在 Eclipse(Java 标准版)中调试它。有什么建议?

回答by BalusC

Ensure that you're using Eclipse for Java EEinstead of Eclipse for standard Java.

确保您使用的是 Java EE的 Eclipse 而不是标准 Java 的 Eclipse。

Once ensured/upgraded, put breakpoints in the servlet code the usual way and run the server in debug modus. Rightclick the server in Eclipse and choose Debuginstead of Start(or click the bug button instead of the green arrow on the button panel of the servers view). Then fire a HTTP request on the servlet using your favourite webbrowser. Eclipse will open and focus the debug panel when the particular code line with the breakpoint is about to be executed.

确保/升级后,以通常的方式在 servlet 代码中放置断点并以调试模式运行服务器。在 Eclipse 中右键单击服务器并选择调试而不是启动(或单击错误按钮而不是服务器视图按钮面板上的绿色箭头)。然后使用您最喜欢的网络浏览器在 servlet 上发出 HTTP 请求。当带有断点的特定代码行即将执行时,Eclipse 将打开并聚焦调试面板。

回答by ThomasRS

Right-click on project -> Debug as -> Debug on server should do the trick

右键单击项目 -> Debug as -> Debug on server 应该可以解决问题