开始在IntelliJ IDEA中开始JSP调试 [英] Stuttering start to JSP debugging in IntelliJ IDEA

查看:577
本文介绍了开始在IntelliJ IDEA中开始JSP调试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用IntelliJ IDEA调试JSP时,我看到在浏览器发出实际请求之前,该JSP被触发了两次.有人知道为什么吗?

When using IntelliJ IDEA to debug a JSP, I'm seeing the JSP get triggered twice before the actual request from the browser. Does anyone know why?

已更新,并在下面进行了servlet测试.

Updated with servlet test below.

我第一次(有效)使用(评估)IntelliJ IDEA.在进行Web应用程序调试时,我看到一个奇怪的行为,表明我在某处配置错误:如果我在代码中设置了一个断点以响应启动页面而运行,则该代码在启动浏览器之前运行两次,然后第三次响应浏览器请求.我想知道我是否在某个地方出错了(或者如果我没出错,那是怎么回事).

I'm using (evaluating) IntelliJ IDEA for (effectively) the first time. When doing web application debugging, I'm seeing an odd behavior that suggests to me I have something misconfigured somewhere: If I have a breakpoint set in code that will run in response to the startup page, the code runs twice before the browser is launched, and then a third time in response to the browser request. I'd like to know whether I may have gone wrong somewhere (or if I haven't gone wrong, what's going on).

A)创建了一个新的Web应用程序项目

A) Created a new web application project

  1. 从头开始创建一个新项目
  2. 给它起一个名字并将其标识为Java模块
  3. 接受默认的src目录
  4. 从所需技术"列表中选择"Web应用程序"
  1. Created a new project from scratch
  2. Gave it a name and identified it as a Java module
  3. Accepted the default src directory
  4. Chose "Web Application" from the Desired Technologies list

这给了我一个标准结构(srcWEB-INF等),其中带有默认的index.jsp.

That gave me a standard structure (src, WEB-INF, etc.) with a default index.jsp in it.

B)在JSP中添加了一些简单的代码来输出日期.

B) Added some simple code to the JSP to output the date.

C)在代码中放置一个断点.

C) Put a breakpoint in the code.

D)在文件|文件管理器中配置了我的Web浏览器.设置|网络浏览器

E)转到运行|编辑配置... 和:

  1. 点击了 [+] | Tomcat服务器|本地
  2. 给它起名字
  3. 单击应用程序服务器下拉列表旁边的 Configure ... 按钮(因为我还没有),然后将其指向我的独立Tomcat6服务器(请参见下文),接受所有默认值
  4. 返回调试配置,告诉它为此配置部署战争爆炸"工件
  5. 在默认的启动URL中添加了一个?foo = bar"查询字符串,因此: http://localhost :8080/?foo = bar (您将在下面看到原因)
  6. 默认情况下保留所有其他内容
  7. 单击确定
  1. Clicked [+] | Tomcat Server | Local
  2. Gave it name
  3. Clicked the Configure... button next to the drop-down list of application servers (since I didn't have any yet) and pointed it at my standalone Tomcat6 server (see below), accepting all the defaults
  4. Back in the debug configuration, told it to deploy the "war exploded" artifact for this configuration
  5. Added a "?foo=bar" query string to the default startup URL, so: http://localhost:8080/?foo=bar (you'll see why below)
  6. Left everything else at defaults
  7. Clicked OK

跑步

  1. 选择运行|调试.它很高兴地启动了Tomcat服务器.
  2. 达到断点.检查请求显示这是来自user-agent"Java/1.6.0_20"的GET.它具有上面配置的查询字符串.没有属性,没有参数,只是查询字符串之一.
  3. 单击恢复程序"按钮(F9).
  4. 它再次达到断点.这也是user-agent"Java/1.6.0_20"的GET,但是没有具有查询字符串.没有属性,没有参数.
  5. 单击恢复程序"按钮(F9).
  6. 它将启动浏览器,然后再次命中断点.这是来自浏览器的GET(带有查询字符串),看起来非常正常.
  1. Choose Run | Debug. It happily starts up the Tomcat server.
  2. It hits the breakpoint. Examining the request shows that this is a GET from user-agent "Java/1.6.0_20". It has the query string configured above. No attributes, no parameters other than the query string one.
  3. Click Resume Program button (F9).
  4. It hits the breakpoint again. This is also a GET from user-agent "Java/1.6.0_20", but it does not have the query string. No attributes, no parameters.
  5. Click Resume Program button (F9).
  6. It launches the browser and hits the breakpoint again. This is a GET from the browser (with the query string) and looks perfectly normal.

我看到了带有和不带有查询字符串的行为,我只是添加了它以查看它何时/是否出现.

I see the behavior both with and without the query string, I just added it to see when/whether it showed up.

如果我创建一个类并从JSP中的代码中使用该类并将断点移到该类的代码中,则该断点确实会全部被击中三次,因此,如果它在做真实的工作(例如,在数据库中查找内容),它确实可以完成工作.我想知道这是幻像预编译调用还是其他东西,但是A)不应,B)似乎不是.

If I create a class and use that class from the code in the JSP and move my breakpoint into the class's code, that breakpoint does get hit all three times, so if it were doing real work (looking something up in a database, for instance), it would really do the work. I wondered if this was some phantom pre-compile call or something, but A) it shouldn't be, and B) it doesn't seem to be.

我想进一步弄清楚该行为,因此我向该项目添加了一个servlet,将其映射到路径/foo,并更改了调试配置以触发

I wanted to tease out the behavior a bit more, so I added a servlet to the project, mapped it to the path /foo, and changed my debug configuration to trigger http://localhost:8080/foo?foo=bar rather than the index page. I also added another JSP to the project, at the root, called another.jsp. This revealed very interesting behavior:

  1. 选择运行|调试.它很高兴地启动了Tomcat服务器.
  2. 它在 servlet 代码中达到了断点.检查请求显示这是来自user-agent"Java/1.6.0_20"的GET.它具有查询字符串.没有属性,没有参数,只是查询字符串之一.
  3. 单击恢复程序"按钮(F9).
  4. 它在 index.jsp (?!)中达到了断点.这也是user-agent"Java/1.6.0_20"的GET,但是没有具有查询字符串.没有属性,没有参数.请注意,index.jsp与启动路径/foo无关.
  5. 单击恢复程序"按钮(F9).
  6. 它启动浏览器,并再次到达servlet中的断点.这是来自浏览器的GET(带有查询字符串),看起来非常正常.
  1. Choose Run | Debug. It happily starts up the Tomcat server.
  2. It hits the breakpoint in the servlet code. Examining the request shows that this is a GET from user-agent "Java/1.6.0_20". It has the query string. No attributes, no parameters other than the query string one.
  3. Click Resume Program button (F9).
  4. It hits the breakpoint in the index.jsp(?!). This is also a GET from user-agent "Java/1.6.0_20", but it does not have the query string. No attributes, no parameters. Note that index.jsp has nothing to do with the startup path /foo.
  5. Click Resume Program button (F9).
  6. It launches the browser and hits the breakpoint in the servlet again. This is a GET from the browser (with the query string) and looks perfectly normal.

another.jsp文件中的断点永远不会命中.因此,我怀疑index.jsp的触发(没有查询字符串)与它是默认的欢迎文件"有关.因此,我在我的web.xml中添加了welcome-file-list,并将another.jsp设置为唯一的welcome-file.果然,现在击中another.jsp中的断点,而不是index.jsp中的断点.

The breakpoint in the another.jsp file is never hit. So I suspected the triggering of the index.jsp (with no query string) relates to it being the default "welcome file." So I added a welcome-file-list to my web.xml and set up another.jsp as the only welcome-file. Sure enough, now the breakpoint in another.jsp gets hit, and not the one in index.jsp.

  • 相当通用的Ubuntu 10.04 LTS桌面安装
  • 新近下载并解压缩的IntelliJ IDEA Ultimate安装(30天试用版)
  • 新下载并解压缩的独立Tomcat6安装(IDEA不喜欢我通过Synaptic完成的集中安装,拆分目录结构使它困惑,因此我停止了该服务器,仅使用了简单的下载和解压缩版本)
  • Sun的Java 6 JDK

提前谢谢!

推荐答案

检查请求显示这是来自用户代理"Java/1.6.0_20"的GET.

Examining the request shows that this is a GET from user-agent "Java/1.6.0_20".

在Tomcat的ROOT上部署Web应用程序时会发生这种情况. Tomcat服务器Eclipse插件将在启动过程中对/进行自检(这将按web.xml的定义间接加载welcome-file).

That happens when you deploy the webapp on ROOT of Tomcat. The Tomcat server Eclipse plugin will do a self-test on / during startup (which indirectly loads the welcome-file as definied in web.xml).

你能做什么?可以使用它,也可以在ROOT以外的环境中部署.

What can you do? Either live with it or deploy on a context other than ROOT.

这篇关于开始在IntelliJ IDEA中开始JSP调试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆