【问题标题】:not able to include .js file in my jsp page无法在我的 jsp 页面中包含 .js 文件
【发布时间】:2014-02-08 04:58:09
【问题描述】:

这是我在 WEB-INF/jsp 文件夹下的文件:

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
        pageEncoding="ISO-8859-1"%>
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
    <title>jQuery Hello World</title>
    <script type="text/javascript" src="/WEB-INF/static/jquery-1.4.2.js"></script>
    </head>
    <script type="text/javascript">
    $(document).ready(function(){

        $("#flag").html("Hello World !! I have come from J Query World");
    });


    </script>

    <body>

    <font color="RED"> Hello World !! I have come from plain world</font>
    <font color="BLUE"> <div id="flag"></div></font>
    </body>
    </html>

我的 jquery 文件在 WEB-INF/static 下 我应该怎么做才能使我的代码正常工作,我认为 .js 文件的路径导致了问题。

【问题讨论】:

  • 您在自己喜欢的浏览器的开发者控制台中看到了哪些(如果有)错误消息?
  • 您为什么要使用 jQuery 1.4.2 编写新代码?它在 jQuery 方面是古老的。就此而言,您为什么在本世纪使用 ISO-8859-1?还是&lt;font&gt; 元素?
  • 您的 HTML 无效,请使用 validator

标签: javascript jquery jsp


【解决方案1】:

WEB-INF 用于保存应用程序的私有文件,客户端不应访问这些文件。

将你的 JS 移动到可以访问的地方。

【讨论】:

  • 问题是无法在 jsp 文件中使用 jquery。即使在 WebRoot 中移动它也无法使用。
【解决方案2】:

问题是你的jsp文件在哪里。

正如你所说,你的jsp路径是:WEB-INF/jsp

所以你的js路径应该是这样的:src="../static/jquery-1.4.2.js"

试试这个,我相信它会奏效。 如果没有,请尝试 src="../WEB-INF/static/jquery-1.4.2.js",否则添加新状态的注释。

【讨论】:

    猜你喜欢
    • 2016-02-19
    • 2015-01-18
    • 1970-01-01
    • 2011-12-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-06-15
    • 1970-01-01
    相关资源
    最近更新 更多