Hi guyz.

I know this is a simple one but Im a bit confused in doing this.

Basically, I want to get the Screen Resoultion of the client machine using my JSP.

I have this code in my Bean.

Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
		 
return screenSize.getWidth();

Problem is it always returns 1152, whatever my screen resoltuion is.

Also I have a JS variable

var scwidth=screen.width

which return the true and correct screen size.

My JS variable changes when I change my screen resoultion while my Java variable does not.

My question really is why does screenSize.getWidth() always return 1152??
(Im using IE 6)

maybe you want getScreenResolution() instead?

Thanks for the suggestion.

Well its the same, always outputs 96 whatever my screen resolution.

I don't know if this will help, but are you restarting the JVM after changing your screen resolution? If not, it could be that Toolkit.getDefaultToolkit() doesn't realize there's been a change.

I really dont know if Im restarting the JVM.

What I really want to do is determine the screen resolution of the machine that is currently viewing my JSP page.

Im just displaying the screen width and its not changing when I change my Screen resolution using Windows Properties.

Is this possible using Java or I have to JS to do this??

Or maybe, the Toolkit.getDefaultToolkit is getting the screen resolution of the server machine and not the client machine??

You could write a little test program that prints the current resolution. If you run on the command line (outside of any IDE) you will be stopping and restarting the JVM each time. This is just to test that getScreenSize really does change when you change the resolution of your screen.

As far as your JSP goes, why not just use your JS variable, since you said in your original post that is working?

Ill try to test the code.

With regards to the JSP page, yes I think ill have to use my JS variable.

My problem is how to pass that JS variable to my JSP variable (",)

But thats on another forum (",)

Thanks for all the help (",).

Just tried kramerd's suggestion in creating a test program and yes, it when I change the screen resolution, the value changes.

But this is using standalone Java and since Im doing JSP this is not applicable.

Thanks for all the help people (",)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.