I have a webpage in which i want the css file to be the same name as a session variable I have set.
For example; If the session variable was "blue", i want the page to load the CSS file blue.css.
I tried something below which didnt work, and I'm now stuck. My knowledge of struts is very limited.
<LINK rel="stylesheet" type="text/css"
href="<html:rewrite page='/css/<c:out value="${brand}"/>.css'/>">
This is the full code listing at the top of my jsp page
<%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean" %>
<%@ taglib uri="http://struts.apache.org/tags-ht开发者_开发百科ml" prefix="html" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-html-el" prefix="html-el"%>
<html:html lang="true">
<head>
<LINK rel="stylesheet" type="text/css" href="<html:rewrite page='/css/${brand}.css'/>">
<html:base/>
I do not know how to find the version of JSP and JSTL I am using. This was a project picked up from someone else and I have never used them before
It isn't working because you put the c:out tag inside the attribute of the html:rewrite tag. Struts tags don't parse when within attribute values.
href="<html:rewrite page="/css/${brand}.css"/>">
according to another user you cant have html rewrite in the attribute but maybe you can do something like below and rewrite the whole link?
<html:rewrite page='<LINK rel="stylesheet" type="text/css" href="/css/${brand}.css"/>'>
Unfortunatily, I couldnt not get any of your answers working. I think it may be a problem with my versions clashing.
For now I have managed to do it by doing;
<%
String brand = (String) session.getAttribute("brand");
if (brand == null || brand.equals("")) {
skin = "standard";
}
%>
<link href="/css/<%=brand%>.css" rel="stylesheet" type="text/css" />
Try this java script, It will work. variable code is a hidden field in ur jsp.
var code=(document.getElementById('code')).value;
var url;
// Dynamically loads the Style Sheet according to the user logged in
if(code !== null)
{
url="<link rel='stylesheet' type='text/css' href='css/"+code+".css' title='default'>";
}
else
{
url="<link rel='stylesheet' type='text/css' href='css/commonStyle.css' title='default'>";
}
if(url !== null)
{
document.write(url);
}
精彩评论