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?
-
4Are you talking about a Java applet, a servlet, or what?Matthew Flaschen– Matthew Flaschen2010-11-16 19:08:17 +00:00Commented Nov 16, 2010 at 19:08
-
About a JSP page to be specific.Demonick– Demonick2010-11-16 20:08:01 +00:00Commented Nov 16, 2010 at 20:08
-
2I'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.Jakub– Jakub2010-11-17 21:13:17 +00:00Commented Nov 17, 2010 at 21:13
2 Answers
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.