当前页面: 开发资料首页 → Eclipse 专题 → 开发一个调试JSP的Eclipse插件
摘要: 本文通过开发一个JSP 编辑器插件的示例,介绍了 Eclipse 中设置 JSP 断点的方法,以及如何远程调试 JSP。
-Xdebug -Xnoagent -Xrunjdwp:transport=dt_socket,address=8000,server=y,suspend=n -Xrunjdwp JVM 加载 jdwp.dll transport=dt_socket 使用 Socket 传输 address 表示调试端口号 server=y 表示 JVM 作为服务器,建立 Socket suspend=n 表示启动过程中,JVM 不会挂起去等待调试客户端连接</td></tr></table>
Components Debugger Interface
/ |-----------------------|
/ | VM |
debuggee ----( |-----------------------| <------- JVMDI - Java VM Debug Interface
\ | back-end |
\ |-----------------------|
/ |
comm channel -( | <--------------- JDWP - Java Debug Wire Protocol
\ |
|---------------------|
| front-end |
|---------------------| <------- JDI - Java Debug Interface
| UI |
|---------------------|
</td></tr></table>com.sun.jdi com.sun.jdi.connect com.sun.jdi.event com.sun.jdi.request本文不对 JDI 进行深入阐述,这里重点介绍 JDI 中与断点相关的接口。
1
2 <head>
3 Hello Example
4 </head>
5 <body>
6 <%@ include file="greeting.jsp" %>
7 </body>
8
</td></tr></table> 2 Goodbye on <%= new java.util.Date() %>
JSP 编译后产生的Hello_jsp.java 如下:
<table borderColor=#cccccc width="90%" align=center bgColor=#e3e3e3 border=1>
Hello_jsp.java:
1 package org.apache.jsp;
2
3 import javax.servlet.*;
4 import javax.servlet.http.*;
5 import javax.servlet.jsp.*;
6
7 public final class Hello_jsp extends org.apache.jasper.runtime.HttpJspBase
8 implements org.apache.jasper.runtime.JspSourceDependent {
9
10 private static java.util.Vector _jspx_dependants;
11
12 static {
13 _jspx_dependants = new java.util.Vector(1);
14 _jspx_dependants.add("/greeting.jsp");
15 }
16
17 public java.util.List getDependants() {
18 return _jspx_dependants;
19 }
20
21 public void _jspService(HttpServletRequest request, HttpServletResponse response)
22 throws java.io.IOException, ServletException {
23
24 JspFactory _jspxFactory = null;
25 PageContext pageContext = null;
26 HttpSession session = null;
27 ServletContext application = null;
28 ServletConfig config = null;
29 JspWriter out = null;
30 Object page = this;
31 JspWriter _jspx_out = null;
32
33
34 try {
35 _jspxFactory = JspFactory.getDefaultFactory();
36 response.setContentType("text/html");
37 pageContext = _jspxFactory.getPageContext(this, request, response,
38 null, true, 8192, true);
39 application = pageContext.getServletContext();
40 config = pageContext.getServletConfig();
41 session = pageContext.getSession();
42 out = pageContext.getOut();
43 _jspx_out = out;
44
45 out.write(" \r\n");
46 out.write("<head> \r\n");
47 out.write("Hello Example");
48 out.write(" \r\n");
49 out.write("</head> \r\n");
50 out.write("<body> \r\n");
51 out.write("Hello There!");
52 out.write(" \r\nGoodbye on ");
53 out.write(String.valueOf( new java.util.Date() ));
54 out.write(" \r\n");
55 out.write(" \r\n");
56 out.write("</body> \r\n");
57 out.write(" \r\n");
58 } catch (Throwable t) {
59 if (!(t instanceof javax.servlet.jsp.SkipPageException)){
60 out = _jspx_out;
61 if (out != null && out.getBufferSize() != 0)
62 out.clearBuffer();
63 if (pageContext != null) pageContext.handlePageException(t);
64 }
65 } finally {
66 if (_jspxFactory != null) _jspxFactory.releasePageContext ( pageContext);
67 }
68 }
69 }
</td></tr></table>SourceDebugExtension_attribute {
u2 attribute_name_index;
u4 attribute_length;
u1 debug_extension[attribute_length];
}
</td></tr></table>
public static void main(String[] args) throws Exception{
String[]files = {
"E:\\Tomcat5_0_5\\work\\Catalina\\localhost\\_\\org\\apache\\jsp\\Hello_jsp.class",
};
for(int k = 0; k < files.length; k++){
String file = files[k];
System.out.println("Class : " + file);
ClassFile classFile = new ClassFile(new DataInputStream(new FileInputStream(file)));
AttributeInfo attributeInfo = classFile.getAttribute("SourceDebugExtension");
System.out.println("attribute name :" + attributeInfo.getName() + "]\n\n");
byte[]bytes = attributeInfo.get();
String str = new String(bytes);
System.out.println(str);
}
}
</td></tr></table>SMAP E:\Tomcat5_0_5\work\Catalina\localhost\_\org\apache\jsp\Hello_jsp.java JSP *S JSP *F + 0 Hello.jsp /Hello.jsp + 1 greeting.jsp /greeting.jsp *L 1:45 2:46 3:47 3:48 4:49 5:50 1#1:51 1:52 2:53 7#0:56 8:57 *E</td></tr></table>
1:45 2:46 3:47 3:48 4:49 5:50(没有源文件代号,默认为Hello.jsp)
开始行号 结束行号
Hello.jsp: 1 -> Hello_jsp.java: 45
2 -> 46
3 -> 47 48
4 -> 49
5 -> 50
1#1:51 1:52 2:53(1#1表示 greeting.jsp 的第1行)
greeting.jsp: 1 -> Hello_jsp.java: 51 52
2 -> 53
7#0:56 8:57(7#0表示 Hello.jsp 的第7行)
Hello.jsp: 7 -> Hello_jsp.java: 56
8 -> 57
</td></tr></table>