Does anyone know how to debug JSP in IntelliJ IDEA?
When I set breakpoint in my JSP files, those breakpoints never seem to take effect. The debugger never hits them. IDEA seems to think that the breakpoints are valid. I do see a red dot placed to the left of the line where I place my breakpoint.
I read in IntelliJ forum in this post that JSP files need to be under web-inf for debugging to work.
But then I also read that JSP files placed under web-inf won't be directly accessible by the user.
For local/remote JSP debugging you'll need to install the JSR45 ㄧ support plugin.
https://jcp.org/aboutJava/communityprocess/final/jsr045/
http://www.jetbrains.com/idea/webhelp/run-debug-configuration-jsr45-compatible-server.html
Go to Preferences > Plugins, search for the JSR45 plugin, and enable it.
Create a run configuration: Run > Run Configuration > click the + button, and pick JSR45 Compatible Server, and then in the dialog that opens, set server host and port. Setting Generic as Application Server worked for me.
Make sure you also set the correct port in Startup/Configuration > Debug.
Now you can set breakpoints in JSP's and debug using the new run configuration.
Anyway, you need to launch the Tomcat in IDEA, not from a remote Tomcat.
------------
Using JDK Logger
JDK Logger can be used to log messages for specific system or application component. The package java.util.logging provides the classes and interfaces of the Java’s core logging facilities.This can be used in JSP for debugging.Let see this in an example below:
Lisitng 2:JDK Logger example
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@page import="java.util.logging.Logger" %>
<html>
<head><title>Logger Example</title></head>
<body>
<% Logger logger=Logger.getLogger(this.getClass().getName());%>
<c:forEach var="toll" begin="1" end="10" step="1" >
<c:set var="mytoll" value="${toll-5}" />
<c:out value="${mytoll}"/></br>
<% String message = "toll="
+ pageContext.findAttribute("toll")
+ " mytollt="
+ pageContext.findAttribute("mytoll");
logger.info( message );
%>
</c:forEach>
</body>
</html>
Output on console:
Jan 22, 2014 10:03:16 AM org.apache.jsp.jskdloggerexample_jsp _jspService
INFO: toll=1 mytollt=-4
Jan 22, 2014 10:03:16 AM org.apache.jsp.jskdloggerexample_jsp _jspService
INFO: toll=2 mytollt=-3
Jan 22, 2014 10:03:16 AM org.apache.jsp.jskdloggerexample_jsp _jspService
INFO: toll=3 mytollt=-2
Jan 22, 2014 10:03:16 AM org.apache.jsp.jskdloggerexample_jsp _jspService
INFO: toll=4 mytollt=-1
Jan 22, 2014 10:03:16 AM org.apache.jsp.jskdloggerexample_jsp _jspService
INFO: toll=5 mytollt=0
Jan 22, 2014 10:03:16 AM org.apache.jsp.jskdloggerexample_jsp _jspService
INFO: toll=6 mytollt=1
Jan 22, 2014 10:03:16 AM org.apache.jsp.jskdloggerexample_jsp _jspService
INFO: toll=7 mytollt=2
Jan 22, 2014 10:03:16 AM org.apache.jsp.jskdloggerexample_jsp _jspService
INFO: toll=8 mytollt=3
Jan 22, 2014 10:03:16 AM org.apache.jsp.jskdloggerexample_jsp _jspService
INFO: toll=9 mytollt=4
Jan 22, 2014 10:03:16 AM org.apache.jsp.jskdloggerexample_jsp _jspService
INFO: toll=10 mytollt=5
-------------------
Debugging JSPs using Eclipse WebTools
Now, you need only start the server in debug mode. You can do this by right-clicking in the JSP editor or on the JSP file in the package explorer and selecting “Debug As > Debug on Server”, or by clicking the “Start in Debug Mode” icon (little picture of a bug) on the “Servers” view (shown below).
When I set breakpoint in my JSP files, those breakpoints never seem to take effect. The debugger never hits them. IDEA seems to think that the breakpoints are valid. I do see a red dot placed to the left of the line where I place my breakpoint.
I read in IntelliJ forum in this post that JSP files need to be under web-inf for debugging to work.
But then I also read that JSP files placed under web-inf won't be directly accessible by the user.
For local/remote JSP debugging you'll need to install the JSR45 ㄧ support plugin.
https://jcp.org/aboutJava/communityprocess/final/jsr045/
http://www.jetbrains.com/idea/webhelp/run-debug-configuration-jsr45-compatible-server.html
Go to Preferences > Plugins, search for the JSR45 plugin, and enable it.
Create a run configuration: Run > Run Configuration > click the + button, and pick JSR45 Compatible Server, and then in the dialog that opens, set server host and port. Setting Generic as Application Server worked for me.
Make sure you also set the correct port in Startup/Configuration > Debug.
Now you can set breakpoints in JSP's and debug using the new run configuration.
Anyway, you need to launch the Tomcat in IDEA, not from a remote Tomcat.
------------
Using JDK Logger
JDK Logger can be used to log messages for specific system or application component. The package java.util.logging provides the classes and interfaces of the Java’s core logging facilities.This can be used in JSP for debugging.Let see this in an example below:
Lisitng 2:JDK Logger example
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@page import="java.util.logging.Logger" %>
<html>
<head><title>Logger Example</title></head>
<body>
<% Logger logger=Logger.getLogger(this.getClass().getName());%>
<c:forEach var="toll" begin="1" end="10" step="1" >
<c:set var="mytoll" value="${toll-5}" />
<c:out value="${mytoll}"/></br>
<% String message = "toll="
+ pageContext.findAttribute("toll")
+ " mytollt="
+ pageContext.findAttribute("mytoll");
logger.info( message );
%>
</c:forEach>
</body>
</html>
Output on console:
Jan 22, 2014 10:03:16 AM org.apache.jsp.jskdloggerexample_jsp _jspService
INFO: toll=1 mytollt=-4
Jan 22, 2014 10:03:16 AM org.apache.jsp.jskdloggerexample_jsp _jspService
INFO: toll=2 mytollt=-3
Jan 22, 2014 10:03:16 AM org.apache.jsp.jskdloggerexample_jsp _jspService
INFO: toll=3 mytollt=-2
Jan 22, 2014 10:03:16 AM org.apache.jsp.jskdloggerexample_jsp _jspService
INFO: toll=4 mytollt=-1
Jan 22, 2014 10:03:16 AM org.apache.jsp.jskdloggerexample_jsp _jspService
INFO: toll=5 mytollt=0
Jan 22, 2014 10:03:16 AM org.apache.jsp.jskdloggerexample_jsp _jspService
INFO: toll=6 mytollt=1
Jan 22, 2014 10:03:16 AM org.apache.jsp.jskdloggerexample_jsp _jspService
INFO: toll=7 mytollt=2
Jan 22, 2014 10:03:16 AM org.apache.jsp.jskdloggerexample_jsp _jspService
INFO: toll=8 mytollt=3
Jan 22, 2014 10:03:16 AM org.apache.jsp.jskdloggerexample_jsp _jspService
INFO: toll=9 mytollt=4
Jan 22, 2014 10:03:16 AM org.apache.jsp.jskdloggerexample_jsp _jspService
INFO: toll=10 mytollt=5
-------------------
Debugging JSPs using Eclipse WebTools
Now, you need only start the server in debug mode. You can do this by right-clicking in the JSP editor or on the JSP file in the package explorer and selecting “Debug As > Debug on Server”, or by clicking the “Start in Debug Mode” icon (little picture of a bug) on the “Servers” view (shown below).
No comments:
Post a Comment