javascript - HTML5 代码未在 JSP 文件中运行

标签 javascript html jsp weblogic jdeveloper

我正在尝试在 HTML5 Canvas 中拖放一个对象。当我从桌面将代码作为 .html 文件运行时,它在我的浏览器中完美运行。当我在 .jsp 文件中运行完全相同的代码时,我没有得到任何输出。为了在 Web 浏览器中显示 jsp 文件的输出,我使用 JDeveloper 11.1.1.7.0 作为 IDE,使用 Oracle weblogic 服务器作为应用服务器。这个版本的IDE支持HTML5吗?

我收到的另一个错误是“不需要元素 Canvas ”

请帮忙..

.jsp 文件中的代码

 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
 "http://www.w3.org/TR/html4/loose.dtd">
 <%@ page contentType="text/html;charset=UTF-8"%>
 <html>
 <head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<title>floorplan</title>
<script type="javascript">

var canvas;
var ctx;
var x = 75;
var y = 50;
var WIDTH = 400;
var HEIGHT = 300;
var dragok = false;

function rect(x,y,w,h) {
ctx.beginPath();
ctx.rect(x,y,w,h);
ctx.closePath();
ctx.fill();
}

function clear() {
ctx.clearRect(0, 0, WIDTH, HEIGHT);
}

function init() {
canvas = document.getElementById("canvas");
ctx = canvas.getContext("2d");
return setInterval(draw, 10);
}
function draw() {
clear();
ctx.fillStyle = "#FAF7F8";
rect(0, 0, WIDTH, HEIGHT);
ctx.fillStyle = "#444444";
rect(x - 15, y - 15, 30, 30);
}

 function myMove(e) {
if (dragok) {
    x = e.pageX - canvas.offsetLeft;
    y = e.pageY - canvas.offsetTop;
}
}

  function myDown(e) {
   if (e.pageX < x + 15 + canvas.offsetLeft && e.pageX > x - 15 + canvas.offsetLeft && e.pageY < y + 15 + canvas.offsetTop && e.pageY > y - 15 + canvas.offsetTop) {
    x = e.pageX - canvas.offsetLeft;
    y = e.pageY - canvas.offsetTop;
    dragok = true;
    canvas.onmousemove = myMove;
  }
 }

 function myUp() {
 dragok = false;
canvas.onmousemove = null;
}

 init();
 canvas.onmousedown = myDown;
 canvas.onmouseup = myUp;
 </script>
    </head>
    <body>
        <div>
             <canvas id="canvas" width="400" height="300">This text is displayed if your browser does not support HTML5 Canvas.</canvas>
         </div>
     </body>
 </html>

最佳答案

为什么要使用 doctype 来限制 HTML4

在 HTML5 的文档类型中单独使用“DOCTYPE HTML”。

关于javascript - HTML5 代码未在 JSP 文件中运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24903273/

相关文章:

java - 从 Java 代码注入(inject) JSP EL 和/或 JSTL 标记

javascript - CSS 中的 Circle div 无法在 Canvas 中正确显示

javascript - 在 .data 或 attr 中保存对象状态 - 性能与 CSS?

html - 按百分比设置 Bootstrap 模态主体高度

html - 文本对某些 div 的不透明度为零,但对其他 div 则不是

jsp - 如何在 JSP 中包含 @include 的运行时文件

java - 如何保护我的jsp页面不被直接访问

javascript - 如何在我的浏览器上永久允许 GPS 定位(本地 Web 应用程序 JAVASCRIPT)

javascript - 不要使用 Stripe 收集邮政编码

java - Jsoup - 提取提取的 URL 的环绕段落