2011-05-03 91 views
0

当我提出包括 <%@ include文件= “../ WEB-INF/JSPF/header.jspf中” %>问题在文件的路径尝试将它们包括到索引页

内的图像时,头不可达也CSS文件不正确链接!!,这里是我的文件层次

enter image description here

在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 

回答

1

你可以尝试把这段代码在你的.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改变<%= request.getContextPath() %>${pageContext.request.contextPath}

+0

这是一个正确的答案,thanx的乌拉圭回合的努力。 – palAlaa 2011-05-03 23:51:02

+1

[JSTL](http://stackoverflow.com/tags/jstl/info)不得与[EL](http://stackoverflow.com/tags/el/info)混淆。你所展示的(正确的*方法)就是EL。 – BalusC 2011-05-04 00:15:04

+0

@BalusC感谢您澄清事情。 – Jakub 2011-05-04 11:21:35

2
  • 获得JSTL
  • 包括标签库在JSP页面中这样的 -

<%@标签库前缀= “C” URI =“http://java.sun.com/ JSP/JSTL /芯”%>

  • 使用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"/>