gpt4 book ai didi

java - 在 Intellij Idea 中调试 JSP 中的内部类

转载 作者:搜寻专家 更新时间:2023-10-31 20:34:38 24 4
gpt4 key购买 nike

我可以在 JSP 中调试内部类吗?

我的应用服务器是tomcat,我用的是Intellij Idea。

普通的jsp断点可以,但是InnerClass断点不行。

在我的测试jsp代码中:

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page import="java.io.IOException" %>
<%
new InnerClass().method_in_inner_class(out);
%>
<%!
class InnerClass {
void method_in_inner_class(JspWriter out) throws IOException {
//set breakpoint under this line
out.print("test1");
}
}
%>

在上面的 jsp 文件中,我在“out.print("test1");”处设置了断点但它不会在线中断。

如何调试到 InnerClass 中?谢谢。

最佳答案

您的代码似乎没问题,除了第二个断点也不起作用,因为该方法仅从 method_in_inner_class 调用。问题是调试 JSP 有点棘手,因为您不是在调试 Java 类。

根据JSR45检查你的服务器是否兼容调试.

如果是,请确保您已正确配置 IDE 和服务器:

For JSP debugging in Intellij there are some configurations that must be in order. The fact that Intellij always allows you to add a breakpoint on a JSP line does not necessarily imply that you’ve configured JSP debugging. In the following I refer to Intellij 8 configuration, w.r.t. previous versions you will need to do similar operations as the concepts are the same.

In order to enable JSP debugging you must do two steps: set a web application configuration in your project and add a web application server configuration.

Web application Configuration: in order to have JSP debugging, you must have a “web” facet in your project structure, pointing to the correct web.xml file. Depending on the kind of web application structure you are using, the facet may be detected automatically by Intellij (go anyway to check what it has done) or you may have to add it manually. Remember in the “Java EE build settings” tab to set as anable “Create web facet exploded directory”; if you don’t want duplications, a trick is just to enable it and point to your already existing directory.

(Web) Application server: Go to “edit configurations”, there you have to add to configurations an application server, not launch the web server as an application like any other. In this way Intellij will be able to intercept JSP calls. In the list of application servers, you should have the default one, Tomcat. Be sure to have a local Tomcat installation before you do this, and point to that when adding the web application server. The last trick is going to the “Deployment” tab and selecting as “Deployment source” the same facet that you configured in the previous step.

The same configuration works if you want to use another web application server, I tested it with the latest Caucho Resin releases and debugging works fine (it didn’t with the previous Intellij and Resin combinations).

If you don’t see Tomcat in the list of available application servers to add, check the plugins in the general Intellij settings pane: in the latest releases, more and more functionality has become “pluggable”, and even very basic functions may be disabled; this plugin is called “Tomcat integration”.

Finally, it is surely not true that JSP files need to be under WEB-INF to be under debugging.

Source: JSP debugging in IntelliJ IDEA

还有 here如果您还没有准备好,可能对您来说是一些有趣的配置。

关于java - 在 Intellij Idea 中调试 JSP 中的内部类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20233085/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com