1

Is there a way to change the css style(defined in the page source) dynamically with Java? I know it is possible to do it with JavaScript. If there isn't, are there other situations where JavaScript is the only choice developing a web app?

3
  • 4
    Are you talking about a Java applet, a servlet, or what? Commented Nov 16, 2010 at 19:08
  • About a JSP page to be specific. Commented Nov 16, 2010 at 20:08
  • 2
    I'm confused by this question, as JS is client side, and JAVA (unless an applet) would be server side.. no? You can do anything you like server side. Commented Nov 17, 2010 at 21:13

2 Answers 2

1

Matthew is right. The question should be specified better.

If you are about applet that is running on current page your can call any javascript including javascript code that changes style of any element.

You just have to add attribute mayscript to applet tag and then use code like the following: JSObject win = (JSObject) JSObject.getWindow(this); win.eval("documeent.getElementById('myelem').style='border-color: red'");

If you are asking about sevlet/jsp you can 1. generate full html code including css 2. bind style element to URL that is mapped to servlet or JSP that generates CSS.

where styles URL brings us to servlet that generates css dynamically using parameter "id".

I hope it helps. Otherwise please try to specify you question.

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

1 Comment

I guess it helps, not sure about syntax for binding the style element to a URL, and dynamically generating css, are there real-world examples out there by any chance?
1

Why don't you use JS in the JSP page like you would in a regular HTML page?

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.