如何调试 gsp 页面? (没有grails,只有gsp)

发布于 2024-08-09 22:10:53 字数 444 浏览 7 评论 0原文

我尝试过netbeans和eclipse,但没有运气......(不能尝试IntelliJ idea)

我快速浏览了一下代码

http://kickjava.com/src/groovy/servlet/TemplateServlet.java.htm

它给我的印象是 .gsp 页面被转换为 .groovy内存中的servlet(groovlet)(我可能是错的)...

所以也许调试gsp并不像我想象的那么容易...

那么,有人可以告诉我该怎么做吗?

pd:显然,我所说的调试是指逐步浏览代码、检查变量、添加监视以及所有这些事情。不是(不太)好的旧 printf 方法......

I've tried with netbeans and eclipse, with no luck... (coudn't try IntelliJ idea)

I gave a quick look ant the code

http://kickjava.com/src/groovy/servlet/TemplateServlet.java.htm

and it gives me the impression that .gsp pages are translated to .groovy servlets (groovlets) in memory (I might be wrong)...

so perhaps it's not so easy to debug gsp as I though...

so, can anybody tell me how to do it?

pd: By debugging I mean things like browsing the code step-by-step, inspecting variables, adding watches, and all those sort of things, obviously. Not the (not so) good old printf approach...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

满地尘埃落定 2024-08-16 22:10:53

GSP 中的大部分逻辑应该封装在 TagLib 中,并且您可以调试它们(至少使用 IntelliJ),就像任何其他 Groovy 代码一样容易。

如果您的 GSP 中确实有大量 scriptlet 代码(您不应该这样做),并且您想要对其进行调试,那么除了 println 之外,您无法执行更多操作。另一种可能性是查看为 GSP 生成的 Groovy 代码的源代码。这可以通过将 showSource 参数附加到 URL 来完成,如 此处

Most of the logic in your GSPs should be encapsulated in TagLibs, and you can debug them (with IntelliJ at least), just as easily as any other Groovy code.

If you do have a lot of scriptlet code in your GSPs (which you shouldn't), and you want to debug into it, you can't do much more than println. One other possibility is to view the source of the Groovy code generated for your GSP. This can be done by appending a showSource parameter to the URL, as described here.

尽揽少女心 2024-08-16 22:10:53

我使用了一个 hack:向任何控制器添加一个方法,例如 static def debugme(def param) { def a = param },并从 gsp 代码中调用它:<% ThisController.debugme (this) %><% ThisController.debugme(params) %>

(您确实知道编辑控制器或视图后不必重新启动应用程序,对吗?)

我也不认为所有逻辑都应该在标签库中:特定于页面的逻辑应该在控制器或视图中清晰可见。我们的大部分逻辑都在控制器或域类中。

I use a hack: add a method to any controller, like static def debugme(def param) { def a = param }, and call it from gsp code: <% ThisController.debugme(this) %>, or <% ThisController.debugme(params) %>

(you do know you don't have to restart application after editing a controller or view, right?)

I also don't think that all the logic should be in taglibs: page-specific logic should be clearly visible in a controller or a view. We have most of the logic in controllers or domain classes.

弱骨蛰伏 2024-08-16 22:10:53

向 Config.groovy 添加设置,生成的 gsp 文件将写入目录: grails.views.gsp.keep generateddir='/some/existing/directory'
(目标目录必须存在并且可写)

更多信息:
http://jira.codehaus.org/browse/GRAILS-4422

应该是可以使用标准 Java 调试器来调试生成的 Groovy 代码。
很久以前我就这么做了(当我创建 grails 补丁时),我想我使用了 jswat (http://code.google.com/p/jswat/)来调试 gsp。我无法让 Eclipse 找到源文件,但这可能在 Spring Tool Suite Eclipse 中工作。
你必须一步一步地调试groovy代码并使用过滤器,否则你可能会丢失步骤点(因为闭包?)。这已经是另一个故事了……

Add a setting to Config.groovy and the generated gsp-files will be written to a directory: grails.views.gsp.keepgenerateddir='/some/existing/directory'
(the target directory has to exists and be writable)

More information:
http://jira.codehaus.org/browse/GRAILS-4422

It should be possible to debug the generated groovy code with a standard Java debugger.
It was a long time ago when I did that (when I created the patch to grails) and I think I used jswat (http://code.google.com/p/jswat/) to debug gsps. I couldn't get eclipse to find the source files, but that's probably working in Spring Tool Suite Eclipse nowadays.
You have to debug groovy code step-by-step/step-into and use filters, otherwise you might lose the step point (because of closures?). That's already another story...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文