【问题标题】:HTML5 code not running in JSP fileHTML5 代码未在 JSP 文件中运行
【发布时间】:2014-07-23 06:25:24
【问题描述】:

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

我遇到的另一个错误是“不需要元素画布”

请帮忙..

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

【问题讨论】:

    标签: javascript html jsp weblogic jdeveloper


    【解决方案1】:

    为什么要使用 doctype 来限制 HTML4

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

    【讨论】:

    • 当我创建 jsp 文件时,Jdeveloper 会自动生成该行。我使用的是 Jdeveloper 版本 11.1.1.7.0...这个版本的 IDE 是否支持 HTML5??
    • 我不确定您使用的 IDE,但大多数最新的浏览器都可以。继续尝试。
    • 是的,我在文件开头添加了 ,现在代码可以正常执行了..谢谢!!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-04-17
    • 2013-09-06
    • 2015-07-29
    • 1970-01-01
    • 1970-01-01
    • 2018-09-20
    • 1970-01-01
    相关资源
    最近更新 更多