palAlaa
palAlaa

Reputation: 9848

Problem in files paths when trying to include them into index page

When I make include <%@include file="../WEB-INF/jspf/Header.jspf" %>

The images inside the header are not reachable also css files are not linked correctly !!, here's the hierarchy of my files

enter image description here

in StudentIndex.jsp I make like this

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

and in the Header.jspf

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

EDIT

when I run StudentIndex.jsp, all the files are running correctly

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

but when the request is forwarded from the servlet to the StudentIndex page no images and no css files are attached

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

Upvotes: 0

Views: 405

Answers (2)

jakubiszon
jakubiszon

Reputation: 3573

You can try to put this code in your .jspf file:

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

You can also change <%= request.getContextPath() %> to ${pageContext.request.contextPath} if you are using jstl EL.

Upvotes: 1

Amol Katdare
Amol Katdare

Reputation: 6760

  • Get JSTL
  • Include taglib in your jsp pages like this -

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

  • Use url tag get rid of your pain. Like this -
<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"/>

Upvotes: 2

Related Questions