Javascript not executed
Javascript not executed
我提前为问这样一个愚蠢的问题道歉,但我似乎无法执行我的Javascript。我从我的完整页面切换到一个简单的示例,以确保我没有做任何太棘手的事情,但我仍然无法让 JS 工作。我将以下代码保存在服务器上名为 index.html 的文件中:
<%@page import="index.jsp" %>
<html>
<head>
<title>Hello World</title>
</head>
<body>
Hello World!<br/>
<script type="text/JavaScript" src="index.jsp">
</script>
Still hello world!
<script type="text/JavaScript">
out.println(" Your IP address is " + request.getRemoteAddr());
alert("Welcome to the boost converter site");
</script>
</body>
</html>
当我转到该页面时,我看到的是:
Hello World
Still Hello World
在 Index.jsp 文件中,我有:
function InitPage(){
out.println("Your IP address is " + request.getRemoteAddr());
}
我知道解决方案非常简单,但我无法想出解决此问题的代码行。我一直在将示例代码复制到我的页面上,只是为了查看其他人的 JS 是否正确执行,但我也没有得到。很确定服务器运行Tomcat。
谢谢
克雷格
out.println()
是Java/JSP,它不是Javascript。
尝试将其替换为document.write('Your IP address is unknown');
<body>
Hello World!<br/>
<!-- Remove this. A .jsp is not Javascript. -->
<!--script type="text/JavaScript" src="index.jsp">
</script-->
Still hello world!
<script type="text/javascript">
/* You can't use request.getRemoteAddr() in Javascript. It's Java. */
document.write("Your IP address is unknown");//+ request.getRemoteAddr());
alert("Welcome to the boost converter site");
</script>
</body>
会不会是你把Java和JavaScript混为一谈了?它们具有完全不同的语法。out.println 是 Java,要写入文档(输出到浏览器窗口),您可以使用 document.write('STRING');在 JavaScript 中。一旦你的 JavaScript 中出现这样的错误,JavaScript 的其余部分也不会被执行。
相关文章:
- jQuery is not loaded
- AngularJS JSON not arriving php
- $rootScope not working
- reactRedux is not defined
- jQuery document.ready not working
- Javascript/Jquery Blob not showing Chrome PDF
- ReferenceError: not defined
- ReferenceError: cordova is not defined @ng-cordova.min.js:7
- Javascript getElementsByTagName not working?
- jQuery's trim()的前缀为not运算符
- Javascript - element.childNodes does not see an append.newch
- SemanticUI模态not onDeny/onApprove事件未激发
- WebkitTransform not fluent
- JQuery.val( ) not working
- Tomcat websocket is not working
- Javascript not executed
- PHP & HTML Form with javascript onsubmit not executed
- Highchart not executed
- Javascript not executed?
- ASP.NET javascript not executed