3

I have a Java Web Project and I want to have a split test in my application. I want to be able to select different header images according to the passed query string. For instance, if the user retrieves the following url:

http://www.website.com/?header=1

Then I show the image A for the header. If the user retrieves the url like this:

http://www.website.com/?header=2

The I show the image B. I'm already receiving the 'header' value in my html by expression language variable. The problem is that I set the image url in a CSS file. How can I pass this variable to the CSS file to load the correct image?

PS: I know I can apply the style in the HTML file, but I want to extract all of my styles in the CSS file.

0

5 Answers 5

2

That's not possible unless you use something like LESS.

What you could do is make separate CSS files, use the querystring to determine your needs with Java Web and load the one you need depending on the situation.

Sign up to request clarification or add additional context in comments.

Comments

1

include 2 different classes for the different background header images in your css, then apply the different class in coding.

.header1 {
background-image: url(background1.jpg);
}

.header2 {
background-image: url(background2.jpg);
}

1 Comment

I'm not using PHP, but it's the same logic. I'll do this. Thanks.
1

If I understood your question correctly, I believe you can do this by applying different CSS class to your header based on what input you gets from header.

1 Comment

Hmm, of course! It's a really good idea. That's the way I'll do. Thank you.
0

You have three basic options:

  • Switch CSS files based on the query parameter, with one CSS file per header image - you can have these just set the header image, and have the static styles in their own file.
  • Use something like LESS or SASS.
  • Write your CSS as a JSP file or dynamically generated via servlet, and change the style dynamically on the server.

Comments

0

Divide your CSS styles into 3 parts:

  • common.css
  • header1.css
  • header2.css

Depending on your headers, you can include either of headerN.css classes. You can solve it also on server side (generating different includes in <head>) or on client side (use javascript to extract the header value and include the proper css dynamically)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.