开发一个调试 JSP 的 Eclipse 插件
2009-12-16 00:00:00 来源:WEB开发网JSR-45 是这样规定的:JSP 被编译成 JAVA 代码时,同时生成一份 JSP 文件名和行号与 JAVA 行号之间的对应表(SMAP)。JVM 在接受到调试客户端请求后,可以根据这个对应表(SMAP),从 JSP 的行号转换到 JAVA 代码的行号;JVM 发出事件通知前, 也根据对应表(SMAP)进行转化,直接将 JSP 的文件名和行号通知调试客户端。
我们用 Tomcat 5.0 做个测试,有两个 JSP,Hello.jsp 和 greeting.jsp,前者 include 后者。Tomcat会将他们编译成 JAVA 代码(Hello_jsp.java),JAVA Class(Hello_jsp.class) 以及 JSP 文件名/行号和 JAVA 行号之间的对应表(SMAP)。
Hello.jsp:
1 <HTML>
2 <HEAD>
3 <TITLE>Hello Example</TITLE>
4 </HEAD>
5 <BODY>
6 <%@ include file="greeting.jsp" %>
7 </BODY>
8 </HTML>
greeting.jsp:
1 Hello There!<P> 2 Goodbye on <%= new java.util.Date() %>
JSP 编译后产生的Hello_jsp.java 如下:
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("<HTML> \r\n");
46 out.write("<HEAD> \r\n");
47 out.write("<TITLE>Hello Example");
48 out.write("</TITLE> \r\n");
49 out.write("</HEAD> \r\n");
50 out.write("<BODY> \r\n");
51 out.write("Hello There!");
52 out.write("<P> \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("</HTML> \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 }
更多精彩
赞助商链接