简体   繁体   中英

Getting the actual jsp line number from a stack trace line number?

Here is the stacktrace:

...
org.apache.jsp.showcustomer_jsp._jspService(showcustomer_jsp.java:128)
org.apache.jasper.runtime.HttpJspBase.service(Unknown Source)

This is what I do:

  1. Get the line number from the stacktrace, in this case 128.
  2. Find the showcustomer_jsp.java file (and it isn't exactly obvious to look in /var/run/tomcat-6/Catalina/localhost/_/org/apache/jsp ).
  3. Open it and go to line 128.
  4. Now, search the .jsp file for the whatever you found on line 128 in the _jsp.java file.
  5. Boom! You're done!

Please, is there a simpler way to do this?

我在Eclipse WTP FAQ上找到了这个页面 ,它解释了如何配置Eclipse,以便您可以单击stacktrace转到生成的java代码。

I don't think you can. The JSP file is compiled into a servlet, and is not run directly. As the exception is thrown from this servlet, the line you have in the stack trace is the one from the class. The original line in the JSP is lost at this point.

Usually it is best to avoid writing code or throwing exceptions from a jsp, and encapsulate your logic in servlets and JSP tags, and use JSTL for control flow (if, forEach, etc.)

I used to program in Lex and Yacc which would generate C code, and you could enable #line pre-processor directives for debugging. When something happened in generated c code, then the IDE was smart enough to open the corresponding lex or yacc file, and not the generated c code. Surly

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM