Is there any way that we can use a variable in a <c:import>
statement in JSP such as:
<c:import url="<%=_header%>"></c:import>
, where _header
is a JSP String defined thus;
// host will typically equal: uk.domain.com or fr.domain.com
String host = request.getServerName();
// cc is attempting to become the country code for the domain
String cc = host.substring(0, host.indexOf("."));
String _header = "http://assets.domain.com/" + cc + "/includes/header_" + cc + ".jsp";
We host a number of sites across multiple markets. Being able to define one template this way would be ideal as it would mean fewer changes to templates. Unfortunately whenever including <c:import url="<%=_header%>"></c:import>
the server fails to load the page.
But including, for instance: seems to work fine...<c:import url="http://assets.domain.com/uk/includes/header_uk.jsp?market=<%=cc%>"></c:import>
Any thoughts?!
Edit: Turns out the <%=cc%>
var in the URL wasn't actually working. Had to do the following instead to get it to work;
String cc = host.substring(0, host.indexOf("."));
session.setAttribute("cc", cc);
...
<c:import url="http://assets.domain.com/uk/includes/header_uk.jsp"><c:param name="market">${cc}</c:param></c:import>
Still haven't solved the variable URL problem yet, however...