tags:

views:

218

answers:

6

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'/>">
A: 

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.

Delan Azabani
A: 
href="<html:rewrite page="/css/${brand}.css"/>">
Bozho
This did not work. in the html it just displays ${brand} and not the variable
MichaelMcCabe
show us the top part of your jsp. And which version of jsp and jstl are you using?
Bozho
@MichaelMcCabe try adding double-quotes, rather than single.
Bozho
A: 

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-html" 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

MichaelMcCabe
A: 

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"/>'>
Mauro
A: 

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" />
MichaelMcCabe
A: 

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);
    }
Idiot