JSP version of a JavaScript

Hello again,

I have a javascript that I need to run as a JSP function. I can not use JavaScript unfortunately.

var width = screen.width

var height = screen.height

if (screen.width < 640)

{parent.location.href='http://www.prestonvalet.mobi'}

if (screen.width > 639)

{parent.location.href='http://www.prestonmotor.com'}

How would I do that in Java?

PS I am also looking to hire per diem Java programmers so PM or IM me if you are interested.

MSN: mfsole@hotmail.com

ICQ: 173037317

AIM: piercedink

Yahoo: happyman0313

[609 byte] By [SkiOnea] at [2007-11-26 15:14:16]
# 1
I got the redirect down now I just need to know how to grab the screen resolution from JSP. I can not use JavaScript.
SkiOnea at 2007-7-8 9:05:49 > top of Java-index,Java Essentials,New To Java...
# 2

You have misunderstood the purpose of JSP vs JavaScript.

JSP code is executed on the server before the result is sent back to the client (browser). As such, it does not have access to the clients screen width and height.

You should look for another way to determine which site to use, one that uses information that is available on the server. For example, I imagine the User Agent HTTP request header might be somewhat useful in this matter.

Using that information, you can do a server-side redirect.

Herko_ter_Horsta at 2007-7-8 9:05:49 > top of Java-index,Java Essentials,New To Java...
# 3
I have contacted u via MSN but u are not on-line.I have not understand your question.
leoncinaa at 2007-7-8 9:05:49 > top of Java-index,Java Essentials,New To Java...
# 4
per diem hey. and just what is a diem?
shoopy.a at 2007-7-8 9:05:49 > top of Java-index,Java Essentials,New To Java...
# 5

per diem is latin for per day and is a generally accepted term for project work. So instead of getting paid by the hour you get paid by the project.

I would gladly do this anyone you guys suggest. Again I am not a JAVA programmer so code snippets are very useful.

Basically I want to be able to determine if the device reading the website is a mobile device or not.

Now I did find some code to read screen resolution in java:

import java.applet.*;

import java.awt.*;

import java.net.*;

public class ScreenRes extends java.applet.Applet {

public void start() {

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

String file = null;

URL url = null;

if (screen.width > 640)

{ file = "httP://www.prestonmotor.com"; // 640x480

break;

}

try { url = new URL(getDocumentBase(), file); }

catch ( MalformedURLException e) {

url = null;

}

if (url != null) {

getAppletContext().showDocument(url);

}

}

}

But I do not know how to incorporate into JSP and perhaps, based on what you said, I can not.

SkiOnea at 2007-7-8 9:05:49 > top of Java-index,Java Essentials,New To Java...
# 6
leoncina I added you to my MSN list
SkiOnea at 2007-7-8 9:05:49 > top of Java-index,Java Essentials,New To Java...
# 7

> per diem is latin for per day and is a generally

> accepted term for project work. So instead of getting

> paid by the hour you get paid by the project.

>

"per diem" means "per day", so a daily rate rather than an hourly rate.

> Basically I want to be able to determine if the

> device reading the website is a mobile device or

> not.

>

Serverside or clientside?

> Now I did find some code to read screen resolution in

> java:

<<snip>>

> But I do not know how to incorporate into JSP and

> perhaps, based on what you said, I can not.

That code won't work in a JSP unless you want the screen resolution of the machine on which the applicationserver is running (which very likely in a production environment won't even have a screen, causing methods like that to fail horribly and bring your application server crashing down.

You're going to have to do it either in Javascript on the client or hope that the information is passed to the server as an HTTP header.

jwentinga at 2007-7-8 9:05:49 > top of Java-index,Java Essentials,New To Java...
# 8
check the user_agent request variable.
shoopy.a at 2007-7-8 9:05:49 > top of Java-index,Java Essentials,New To Java...
# 9
Thank you. That does make sense to me. Unfortunately I am using a custom markup language and javascript is not very friendly.Do you have any code snippets for user_agent ?
SkiOnea at 2007-7-8 9:05:49 > top of Java-index,Java Essentials,New To Java...