Saturday, 14 September 2013

HTML base element doesn't append context to head links from JSP tag file

HTML base element doesn't append context to head links from JSP tag file

I am having issues with the HTML base element not appending the context to
any link or script URL's. I am dynamically creating the base url within
the jsp, and the correct context is set in the source. However, all of the
references in the head give 404's in the browser dev console, and the page
obviously has no css. I am setting the HTML head with a jsp .tag file.
Here is my index.jsp file
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="tag" tagdir="/WEB-INF/tags"%>
<c:set var="req" value="${pageContext.request}" />
<c:set var="uri" value="${req.requestURI}" />
<!DOCTYPE html>
<html>
<head>
<base href="${req.contextPath}" >
<tag:head page="home" />
</head>
<body>
</body>
</html>
So I am setting the base as the first thing in the head, and then setting
whatever the head.tag file has. I have also tried setting the base in the
head.tag file and that doesn't work either. Here is the head.tag file
<%@ tag language="java" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ attribute name="page" required="true" %>
<link rel="shortcut icon" type="image/x-icon" href="images/favicon.ico"/>
<title> <c:out value="${page}" /> </title>
<meta charset="UTF-8">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link rel="stylesheet" href="css/layout.css" type="text/css" />
<link rel="stylesheet" href="stylesheet.css" type="text/css" />
<link rel="stylesheet" href="css/slide.css" type="text/css" media="screen" />
<link rel="stylesheet" href="css/jquery-ui/jquery-ui-1.10.3.custom.css"
type="text/css" media="screen" />
<script type="text/javascript" src="js/jquery-1.10.1.min.js"></script>
<script type="text/javascript"
src="js/jquery-ui-1.10.3.custom.min.js"></script>
<script type="text/javascript" src="js/ajax.js"></script>
<script type="text/javascript" src="js/onLoad.js"></script>
<script type="text/javascript" src="js/cookies.js"></script>
<script type="text/javascript" src="js/spin.js"></script>
<script type="text/javascript" src="js/slide.js"></script>
So for example, the browser is looking in
http://localhost:8080/css/layout.css for the layout stylesheet, when it
should be looking in http://localhost:8080/WebApp/css/layout.css The base
element in the html source when the page renders is '' which is valid
because it is an absolute url and defines the root. I even tried setting
the whole url inclidung http://localhost:8080 Any ideas as to whats going
on here? thanks for your help!

No comments:

Post a Comment