【问题标题】:JSP couldnt link css files and js filesJSP无法链接css文件和js文件
【发布时间】:2014-12-31 01:53:09
【问题描述】:

我是 jsp 的新手。我正在使用 netbeans 的 Glassfish 服务器。问题是我可以将我的 jsp 文件与 css 和 javascripts 链接起来。这是我的文件结构的格式

Web Pages  
 --Web-Inf  
 --assets  
    --css   
     --style.css  
  --js  
 --jquery.js  
 --includes    
--header.jsp  
--footer.jsp  
--sidebar.jsp  
 --pages    
--home.jsp  
 --index.jsp    

这是我的 index.jsp 中的代码

<%@include file="includes/header.jsp" %>

<%
    if (request.getParameter("page") == null) {
        %>
        <%@include file="pages/home.jsp" %>
        <%
    } else {
        %>

        <%
    }
%>

    <%@include file="includes/sidebar.jsp" %>
</div>

<!--Latest end-->

<%@include file="includes/footer.jsp" %>

这是我在 header.jsp 中的代码

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

【问题讨论】:

  • 您在加载 css 时收到 404 错误。是在web-inf里面吗?
  • @SanKrish 是的,我收到 404 错误,并且 css 文件夹位于 web-inf 之外
  • 您访问应用程序时使用的 url 是什么?
  • @sadasidha 它是localhost:8080/pricingsystem
  • 目录名称应该是“Web Pages”而不是“Web-Pages”,名称中没有'-'。

标签: java javascript css jsp


【解决方案1】:

你可以使用 index.jsp 的相对 url

<link href="assets/css/bootstrap.min.css" rel="stylesheet">

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-02-04
    • 2023-01-26
    • 2020-11-01
    • 1970-01-01
    • 1970-01-01
    • 2014-09-05
    • 1970-01-01
    相关资源
    最近更新 更多