Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Debug javascript inside jsp page with Chrome?

Is there a way to debug javascript which is inside a jsp page, like this with chrome:

<script>
var error = "${error}";

if(error != ""){
    alert(error);
}
</script>

In the developer Tools Window I can only find .js files.

like image 416
PogoMips Avatar asked Feb 15 '13 19:02

PogoMips


People also ask

Can we put breakpoint inside JSP?

With WebTools installed, you can add one or more breakpoints by opening an editor on the JSP file, and double-clicking in the left-hand column. A breakpoint icon will appear as shown below.


2 Answers

Put magic word debugger, open developer tools, and reload the page to debug it. It works like breakpoint:

<script>
var error = "${error}";

debugger

if(error != ""){
    alert(error);
}
</script>
like image 194
dfsq Avatar answered Oct 13 '22 11:10

dfsq


You aren't going to see a JSP file in your browser, as JSPs are server-side and are interpreted there and ultimately turned into HTML that is then sent to your browser. In the Chrome Dev Tools, your Sources tab should list the page itself (your page's markup in its entirety) in the sources list on the left (it may be named whatever you named your page, or it may be named something generic like (program)). You can find your JavaScript code in there (since the JS that you put in your JSP should have ultimately been rendered to the page) and you should be able to place breakpoints in it and do anything else you could with a plain .js file.

like image 40
ajp15243 Avatar answered Oct 13 '22 10:10

ajp15243