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)

Re: Getting Screen Size 80 80

maybe you want getScreenResolution() instead?

Re: Getting Screen Size 80 80

Thanks for the suggestion.

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

Re: Getting Screen Size 80 80

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.

Re: Getting Screen Size 80 80

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??

Re: Getting Screen Size 80 80

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?

Re: Getting Screen Size 80 80

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 (",).

Re: Getting Screen Size 80 80

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 1.18 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.