不许代码码上红 2022-09-23 22:53 采纳率: 50%
浏览 62
已结题

html转换为jsp页面失败

一个html页面

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>烟花</title>


<style>
body,
html {
  margin: 0;
  padding: 0;
  overflow:hidden;
}
</style>

</head>
<body>

<canvas></canvas>

<script>
const rndColor = () => {
    const base  = Math.random() * 360 | 0;
    const color = (275 * (base / 200 | 0)) + base % 200;
    return fac => `hsl(${color}, ${(fac || 1) * 100}%, ${(fac || 1) * 60}%)`;
};

class Battery
{
    constructor(fireworks) {
        this.fireworks = fireworks;
        this.salve = [];
        this.x     = Math.random();
        this.t     = 0;
        this.tmod  = 20 + Math.random() * 20 | 0;
        this.tmax  = 500 + Math.random() * 1000;

        this._shot = salve => {
            // console.log(this.x * this.fireworks.width, salve.y);
            if (salve.y < salve.ym) {
                salve.cb = this._prepareExplosion;
            }

            salve.x += salve.mx;
            salve.y -= 0.01;

            const r = Math.atan2(-0.01, salve.mx);

            this.fireworks.engine.strokeStyle = salve.c(.7);
            this.fireworks.engine.beginPath();

            this.fireworks.engine.moveTo(
                (this.x + salve.x) * this.fireworks.width + Math.cos(r) * 4,
                salve.y * this.fireworks.height + Math.sin(r) * 4
            );

            this.fireworks.engine.lineTo(
                (this.x + salve.x) * this.fireworks.width + Math.cos(r + Math.PI) * 4,
                salve.y * this.fireworks.height + Math.sin(r + Math.PI) * 4
            );

            this.fireworks.engine.lineWidth = 3;
            this.fireworks.engine.stroke();

            // this.fireworks.engine.fillRect((this.x + salve.x) * this.fireworks.width, salve.y * this.fireworks.height, 10, 10);
        };

        this._prepareExplosion = salve => {
            salve.explosion = [];

            for (let i = 0, max = 32; i < max; i++) {
                salve.explosion.push({
                    r : 2 * i / Math.PI,
                    s : 0.5 + Math.random() * 0.5,
                    d : 0,
                    y : 0
                });
            }

            salve.cb = this._explode;
        };

        this._explode = salve => {

            this.fireworks.engine.fillStyle = salve.c();

            salve.explosion.forEach(explo => {

                explo.d += explo.s;
                explo.s *= 0.99;
                explo.y += 0.5;

                const alpha = explo.s * 2.5;
                this.fireworks.engine.globalAlpha = alpha;

                if (alpha < 0.05) {
                    salve.cb = null;
                }

                this.fireworks.engine.fillRect(
                    Math.cos(explo.r) * explo.d + (this.x + salve.x) * this.fireworks.width,
                    Math.sin(explo.r) * explo.d + explo.y + salve.y * this.fireworks.height,
                    3,
                    3
                );
            });

            this.fireworks.engine.globalAlpha = 1;
        }
    }

    pushSalve() {
        this.salve.push({
            x: 0,
            mx: -0.02 * Math.random() * 0.04,
            y: 1,
            ym: 0.05 + Math.random() * 0.5,
            c: rndColor(),
            cb: this._shot
        });
    };

    render() {

        this.t++;

        if (this.t < this.tmax && (this.t % this.tmod) === 0) {
            this.pushSalve();
        }

        let rendered = false;

        this.salve.forEach(salve => {

            if (salve.cb) {
                rendered = true;
                salve.cb(salve);
            }

        });

        if (this.t > this.tmax) {
            return rendered;
        }

        return true;
    }
}

class Fireworks
{
    constructor() {
        this.canvas = window.document.querySelector('canvas');
        this.engine = this.canvas.getContext('2d');
        this.stacks = new Map();

        this.resize();
    }

    resize() {
        this.width  = window.innerWidth;
        this.height = window.innerHeight;

        this.canvas.setAttribute('width', this.width);
        this.canvas.setAttribute('height', this.height);
    }

    clear() {
        this.engine.clearRect(0, 0, this.width, this.height);
        this.engine.fillStyle = '#222';
        this.engine.fillRect(0, 0, this.width, this.height);
    }

    addBattery() {
      const bat = new Battery(this);
      this.stacks.set(Date.now(), bat);  
    }
  
    render() {

        if (Math.random() < 0.05) {
          this.addBattery();
        }
      
        this.clear();

        this.stacks.forEach((scene, key) => {

            const rendered = scene.render();

            if (!rendered) {
                this.stacks.delete(key);
            }
        });

        requestAnimationFrame(this.render.bind(this));
    }

    run() {
        for(let i = 0; i < 5; i++) {
          this.addBattery();
        }
        window.addEventListener('resize', this.resize.bind(this));
        this.render();
    }
}

a = new Fireworks();
a.run();</script>

</body>
</html>


加上头标签改成jsp页面前

img

加上头标签改成jsp页面后

img

然后在内部跳转到jsp页面问题出现

img

求解决!

  • 写回答

5条回答 默认 最新

  • Hello World, 2022-09-24 10:08
    关注

    把JS里的$符号前加一个\就可以了

    return fac => `hsl(\${color}, \${(fac || 1) * 100}%, \${(fac || 1) * 60}%)`;
    
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
  • CSDN-Ada助手 CSDN-AI 官方账号 2022-09-23 23:05
    关注
    • 关于该问题,我找了一篇非常好的博客,你可以看看是否有帮助,链接:html(jsp)登录页面
    评论
  • 爱音斯坦牛 全栈领域优质创作者 2022-09-24 00:37
    关注

    1.是jQuery和JSTL冲突了,即$这个符号在jQuery和JSTL都有用到,所以冲突了,最简单的解决办法就是不用jQuery里面的$,把$符号改成jQuery改成就好了。
    2.如果是用${}的方式取值的话,把他改成+号拼接参数就行。
    总之不要用$符。
    有帮助的话采纳一下哦!

    评论 编辑记录
    1人已打赏
  • 夜郎king 2022博客之星IT其它领域TOP 12 2022-09-24 08:54
    关注

    $在JSP里面是一个表达式的固定写法,在html中可以正常解析,到了jsp,根据你传的值,jsp读不到就报错了。

    解决办法就修改在js的复制方式,将值先计算出来,避免这种情况出现。

    评论
  • Saiyueze 2022-09-24 10:42
    关注

    ${} 是JSP中 EL表达式的表示方式,按照你的描述你使用了jQuery这个库,解决办法如下:
    把使用jQuery的代码的$部分全部替换成 jQuery,比如你原来是 ${color} 换成 jQuery{color} ;也就是使用jQuery库本身为了解决$ 冲突问题同时提供了同等地位的jQuery对象。

    转换后应该就可以了...

    评论
查看更多回答(4条)

报告相同问题?

问题事件

  • 系统已结题 10月2日
  • 已采纳回答 9月24日
  • 创建了问题 9月23日

悬赏问题

  • ¥15 单点式登录SSO怎么爬虫获取动态SSO_AUTH_ACCESS_Token
  • ¥15 MATLAB中的fft问题
  • ¥30 哈夫曼编码译码器打印树形项目
  • ¥20 求完整顺利登陆QQ邮箱的python代码
  • ¥15 怎么下载MySQL,怎么卸干净原来的MySQL
  • ¥15 网络打印机Ip地址自动获取出现问题
  • ¥15 求局部放电案例库,用于预测局部放电类型
  • ¥100 QT Open62541
  • ¥15 stata合并季度数据和日度数据
  • ¥15 谁能提供rabbitmq,erlang,socat压缩包,记住版本要对应