Java 从 Eclipse 调试 JSP

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/123462/
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-08-11 08:33:58  来源:igfitidea点击:

debug JSP from eclipse

javaeclipsejspservletsdebugging

提问by Dónal

Does anyone know of a good tool for debugging JSPs from within Eclipse? I'd like to be able to set and watch breakpoints, step through the Java code/tags, etc within Eclipse while the app is running (under JBoss in my case).

有谁知道在 Eclipse 中调试 JSP 的好工具?我希望能够在应用程序运行时(在我的情况下在 JBoss 下)在 Eclipse 中设置和观察断点、单步执行 Java 代码/标签等。

Presumably, it's reasonably straightforward to debug the servlet class that's generated from a JSP, but it's also fairly unappealing.

据推测,调试从 JSP 生成的 servlet 类相当简单,但它也相当不吸引人。

回答by Dónal

If you have WTPinstalled, you can set breakpoints within a JSP and they work fine in a regular "remote debug" session. However, once you've stopped on a breakpoint, stepping through the code is nigh on impossible and finding whatever it is that you wish to inspect takes a lot of digging around in the "Variables" view.

如果您安装了WTP,您可以在 JSP 中设置断点,并且它们在常规的“远程调试”会话中工作正常。然而,一旦您在断点处停止,单步执行代码几乎是不可能的,找到您想要检查的任何内容都需要在“变量”视图中进行大量挖掘。

回答by Kevin Day

If you are having to use a debugger in a JSP, chances are very good that you are doing things in the JSP that you shouldn't be. I recommend that you think very hard about whether your current implementation is using good MVC design practice. JSPs really should be about presentation, which should rarely (if ever) require debugging.

如果您必须在 JSP 中使用调试器,那么您很可能在 JSP 中做了不该做的事情。我建议您仔细考虑您当前的实现是否使用了良好的 MVC 设计实践。JSP 真的应该是关于展示的,它应该很少(如果有的话)需要调试。

If you have certain logic constructs that you are having to implement in JSP, consider implementing them using a custom tag (which is easy to debug in an IDE), or do the processing in controller servlet that presents the data in an easy to digest form for the JSP.

如果您有某些必须在 JSP 中实现的逻辑结构,请考虑使用自定义标记(这在 IDE 中易于调试)来实现它们,或者在控制器 servlet 中进行处理,以易于理解的形式呈现数据对于 JSP。

回答by Tracey

Apparently, Eclipse has a troubleshooting pageon this, though when I tried it I did get a 404 with it. Hopefully this can at least get you started in a good direction.

显然,Eclipse 有一个关于此的故障排除页面,但当我尝试它时,我确实得到了一个 404。希望这至少可以让你朝着一个好的方向开始。

回答by Esteban

Within Eclipse, you can put breakpoints to your jsp file, step through the Java code/tags, etc.
However the only view you can use while debugging is the Variablesview to inspect the value of any variable.

And one more thing, you can not see the value for example of this expression:
<%= response.encodeURL("ProcessLogin.jsp")%>
just the value of the variable response.

在 Eclipse 中,您可以在 jsp 文件中放置断点,单步执行 Java 代码/标记等。
但是,您在调试时可以使用的唯一视图是Variables视图来检查任何变量的值。

还有一件事,你看不到这个表达式的值:
<%= response.encodeURL("ProcessLogin.jsp")%>
只是变量response的值。