【问题标题】:CSS and JS File Not loadedCSS 和 JS 文件未加载
【发布时间】:2017-04-25 09:03:12
【问题描述】:

这是我的项目结构,当我试图在服务器 CSS 上运行这个项目时,JS 文件无法加载。

下面是我用来添加 CSS/JS 的代码

<script src="js/jquery.min.js"></script>

<link href="css/form.css" rel="stylesheet" type="text/css" media="all" />
<link href="css/style.css" rel="stylesheet" type="text/css" media="all" />

我正在使用 MyEclipse 作为 IDE

【问题讨论】:

  • 有没有人看到代码,因为我可能没瞎
  • 现在你可以看到它@LukasA

标签: javascript css spring myeclipse


【解决方案1】:

如果你在jsp中使用,试试这样使用

<script src="${pageContext.request.contextPath}/js/jquery.min.js"></script>

<link rel="stylesheet" href="${pageContext.request.contextPath}/css/form.css">
<link rel="stylesheet" href="${pageContext.request.contextPath}/css/style.css">

【讨论】:

    【解决方案2】:

    你必须把你的 web 项目名称放在你的 css 文件的地址路径之前

    <link rel="stylesheet" href="/YourProjectName/css/XXX.css" type="text/css">
    

    或者以更动态的方式:

    <link rel="stylesheet" href="${pageContext.request.contextPath}/css/XXX.css" />
    

    【讨论】:

      【解决方案3】:

      在你的jsp上定义这个变量。

      <%
      String scheme = request.getScheme();
      String serverName = request.getServerName();
      int serverPort = request.getServerPort();
      String contextPath = request.getContextPath();
      String uri = scheme + "://" + serverName + ":" + serverPort + contextPath ;
      String uriGeneral = scheme + "://" + serverName + ":" + serverPort;
      %>
      

      当您需要 css 或 js 时,只需这样做:

       <link type="text/css" rel="stylesheet" href="<%=uriGeneral%>/yourModule/resources/css/Style.css"/>
      
       <script type="text/javascript" src="<%=uriGeneral%>/YourModule/resources/js/jquery/jquery.js"></script>
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2019-08-14
        • 1970-01-01
        • 2021-05-18
        • 2017-05-07
        • 2016-11-11
        • 2019-06-07
        • 1970-01-01
        • 2017-11-18
        相关资源
        最近更新 更多