• Post Reply Bookmark Topic Watch Topic
  • New Topic

getting screen resolution using JSP  RSS feed

 
tee mahmood
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all, I want to get the screen resolution using JSP, does anyone have any idea how to do this?
I've checked the header info from the browswer and its not stored
there. How do people normally do it?
 
tee mahmood
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
is there a kind person here to give me some help?
 
Cynthia Yao
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Screen resolution? Just wonder why do you need to find out that. Anyway, that is client side, do you search through javascript? If you are using applet, try this:
Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize() ;
 
karl koch
Ranch Hand
Posts: 388
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
are you in a kind of hurry ?
you cannot get the screen size just by jsp since this is client side (as already mentioned in the post above).
but try this:
on first page (eg. index.html) , read the screensize with JavaScript, forward to the second page with the screensize as parameters in the url. the second page reads the parameters (the second page would be a servlet or a jsp) and stores it somewhere (session, db...).

karl
 
tee mahmood
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks for reply but reason I needed to know was because I do
both server side & client side work. I'll try the above javascript solution.
cheers
 
Julio Lopez
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is a javascript function that shows how you get that information and forward to the appropriate place.
function screenRes() {
var theScreenWidth = screen.width
var theScreenHeight = screen.height
if ( (theScreenWidth > 800) && (theScreenHeight > 600) ) {
window.document.location = "/servlet/Foo"
}
else {
window.document.location = "/login/loginError.jsp"
}
}
or if you want a servlet to do the processing and forwarding
function screenRes() {
var theScreenWidth = screen.width
var theScreenHeight = screen.height
window.document.location = "/servlet/Whatever?screenWidth=" + theScreenWidth + "&screenHeight=" + theScreenHeight
}
The HTML document the javascript will reside in should be pretty minimal and should look something like,
<HTML>
<HEAD>
<SCRIPT LANGUAGE="JavaScript">
... above code
</SCRIPT>
</HEAD>
<BODY onLoad="screeRes();">
</BODY>
</HTML>
Obviously the screen properties can only be extracted from a javascript enabled browser and I have no idea how cross-browser the capability is.
Julio Lopez
M-Group Systems
 
tee mahmood
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thankx Julio
works a treat in javascript enabled browsers.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!