【问题标题】:Problem in files paths when trying to include them into index page尝试将文件路径包含到索引页面时出现问题
【发布时间】:2011-05-03 22:30:45
【问题描述】:

当我包含

标头内的图像无法访问,css文件也没有正确链接!!,这是我的文件的层次结构

在 StudentIndex.jsp 中我是这样制作的

<link type="text/css" rel="stylesheet" href="../css/StudentStyle.css"/>
<%@include file="../WEB-INF/jspf/Header.jspf" %>

并在 Header.jspf 中

<link href="../css/Style.css" type="text/css" rel="stylesheet"/>
<img src="../images/iuglogo.gif" alt="IUG logo" id="IUGlogoStyle"/>

编辑

当我运行 StudentIndex.jsp 时,所有文件都运行正常

http://localhost:8080/OnlineQuerySystemNew/Student/StudentIndex.jsp

但是当请求从 servlet 转发到 StudentIndex 页面时,没有附加图像和 css 文件

http://localhost:8080/OnlineQuerySystemNew/StudentManagementServlet?param=activationOptions

【问题讨论】:

    标签: java jsp path


    【解决方案1】:
    • 获取JSTL
    • 像这样在你的 jsp 页面中包含 taglib -

    • 使用url tag 摆脱你的痛苦。像这样 -
    <link rel="stylesheet" type="text/css" href='<c:url value="/css/Style.css" />' />
    <img src='<c:url value="/images/iuglogo.gif" />' alt="IUG logo" id="IUGlogoStyle"/>
    

    【讨论】:

      【解决方案2】:

      您可以尝试将此代码放入您的 .jspf 文件中:

      <link href="<%= request.getContextPath() %>/css/Style.css" type="text/css" rel="stylesheet"/>
      <img src="<%= request.getContextPath() %>/images/iuglogo.gif" alt="IUG logo" id="IUGlogoStyle"/>
      

      如果您使用 jstl EL,也可以将 &lt;%= request.getContextPath() %&gt; 更改为 ${pageContext.request.contextPath}

      【讨论】:

      • JSTL 不得与 EL 混淆。您所展示的(作为 正确的 方法)只是 EL。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-07-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-01-30
      相关资源
      最近更新 更多