Debugging a Java program from Tomcat (JSP)

I don’t know why I never tried to use the debugger to go through my program and see what happens, probably because I'm used to using interpreted languages ​​such as PHP, where it is very easy to add debugging code ( print_r) and view the changes in real time.

However, with this new Java project, it seems to me that I should learn the right ways to debug.

So, this program, which I did not write, runs on Tomcat and uses basic JSPs. The problem is that when I try to access a specific JSP page, it throws an exception and gives me a stack from what happened:

org.apache.jasper.JasperException: java.lang.NullPointerException
    org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:503)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:433)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:363)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:306)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
    org.sgrp.singer.filters.SingerLoginFilter.doFilter(SingerLoginFilter.java:128)

How do I get through my program with a tool like JDB? I cannot go through a specific class because I need to imitate what my JSP does ... I would like to do this through the command line without using an IDE.

+3
source share
4 answers

An alternative solution that might be easier to use than connecting a debugger to Tomcat:

First look at the call stack. Below you will see your class with a name org.sgrp.singer.filters.SingerLoginFilter. The problem here is on line 128 of the method doFilter.

The first line indicates org.apache.jasper.JasperException: java.lang.NullPointerException. This means that you used an object whose value is null in line 128 of the specified class.

, , . , /.

. , .

+1

-, Java , :

-Xdebug -Xrunjdwp:transport=dt_socket,address=8000,server=y,suspend=n

- , . IDE . (, ) . .

: -JSP (error.jsp ) stacktrace catch (ex.getStracktrace), stacktrace (ex.getCause().getStacktrace()). .

: , IDE , . Tomcat , .

+2

JDB , .

, : http://www.javaworld.com/javaworld/javaqa/2000-06/04-qa-0623-jdb.html

, Tomcat, , , :

-Xdebug -Xnoagent -Djava.compiler = NONE-Xrunjdwp: server = y, transport = dt_socket, address = 8000, suspend = y

8000 . basicaly jvm .

, tomcat, , .

JDB :

jdb -attach localhost: 8000

, localhost , tomcat , 8000 , jvm tomcat.

, , help jdb.

+1

eclipse, tomcat eclipse, eclipse , eclipse, jboss.

, jvm - .

0
source

Source: https://habr.com/ru/post/1772847/


All Articles