使用 Chrome 在 jsp 页面中调试 javascript?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14902094/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-24 18:16:24  来源:igfitidea点击:

Debug javascript inside jsp page with Chrome?

javascriptdebugginggoogle-chrome

提问by PogoMips

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

有没有办法调试jsp页面内的javascript,就像这样用chrome:

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

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

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

在开发人员工具窗口中,我只能找到 .js 文件。

回答by dfsq

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

放入魔术字debugger,打开开发者工具,重新加载页面进行调试。它的工作原理类似于断点:

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

debugger

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

回答by ajp15243

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 .jsfile.

您不会在浏览器中看到 JSP 文件,因为 JSP 是服务器端并在那里被解释并最终转换为 HTML,然后发送到您的浏览器。在 Chrome Dev Tools 中,您的 Sources 选项卡应该在左侧的源列表中列出页面本身(您页面的整个标记)(它可能以您命名的任何页面命名,或者它可能命名为类似的通用名称(program))。您可以在其中找到您的 JavaScript 代码(因为您放入 JSP 中的 JS 最终应该已呈现到页面上),您应该能够在其中放置断点并使用普通.js文件执行您可以执行的任何其他操作。