/    Sign up×
Community /Pin to ProfileBookmark

Java redirect script

Hi

I found this script:

<script language=’JAVASCRIPT’ type=’TEXT/JAVASCRIPT’>
<!–
if ((navigator.appName==”Microsoft Internet Explorer”) || (navigator.appName==”Netscape”))
{

if (navigator.appName==”Microsoft Internet Explorer”)
window.location = “pc/index.htm”;
else
window.location = “pc/index.htm”;
}
else
window.location = “phone/index.htm”;
//–></script>

Unfortunately, it’s in Javascript and I need it in Java.

Does anybody know the Java code for this Javascript code?

Thanks

to post a comment
Java

11 Comments(s)

Copy linkTweet thisAlerts:
@ray326Sep 25.2004 — It would look something like this:
<i>
</i>&lt;%
if (request.getHeader("user-agent").indexOf("MSIE") &gt; -1)
response.sendRedirect("pc/index.htm");
else if (request.getHeader("user-agent").indexOf("Firefox") &gt; -1)
response.sendRedirect("pc/index.htm");
else
response.sendRedirect("phone/index.htm");
%&gt;
Copy linkTweet thisAlerts:
@Frank1984authorSep 26.2004 — It doesn't seem to work, look:

http://www.voordeligewebsites.com/mpoints/

Does anybody know what I am doing wrong?

Thanks!
Copy linkTweet thisAlerts:
@Khalid_AliSep 26.2004 — rays suggestion above presumes that you have a server that understands jsp tags and is a servlet container...the above code should work from any web server that supports jsp/servlet technologies.
Copy linkTweet thisAlerts:
@Frank1984authorSep 26.2004 — [i]Originally posted by Khalid Ali [/i]

[B]rays suggestion above presumes that you have a server that understands jsp tags and is a servlet container...the above code should work from any web server that supports jsp/servlet technologies. [/B][/QUOTE]


Well, it looks like my server doesn't support this. Do you guys know any other code that would work?

Thanks in advance for your efforts!
Copy linkTweet thisAlerts:
@Khalid_AliSep 26.2004 — try finding out that if your server supports PHP(Iam guessing it does).If it does then post your question in PHP and you will be all set.
Copy linkTweet thisAlerts:
@Frank1984authorSep 26.2004 — Well, the problem is it has to be Java. This is why:

I'm working with a client who's in the UMTS business. I have to create for him two different sites that will be accesible on one domainname. So I have to use a redirect script.

The problem is these UMTS phones only support Java and HTML. So I have to use Java to redirect the user to the right website.

So, when a PC is visiting the website he will be directed to the big website and when a UMTS phone is visiting the website he will be directed to the small website.

So I need a Java applet that sais that when you are visiting the site with the IE or with Netscape you'll go to the big site, otherwise you'll go to the other site. What also would be good is that when you are visiting with a screen resolution less than 640 x 480 you go to the small site and otherwise you go to the bg site.

Several days now I'm looking on the internet for the right applet and I could not find it. I promised my client that I would implement such a Java redirect script so I really hope you guys can help me out.

Thanks!
Copy linkTweet thisAlerts:
@IncaWarriorSep 26.2004 — you have something against opera?
Copy linkTweet thisAlerts:
@JPnycSep 26.2004 — Yep. Most of em are in Italian. I'm not fluent in Italian.
Copy linkTweet thisAlerts:
@ray326Sep 26.2004 — [i]Originally posted by Frank1984 [/i]

[B]Well, the problem is it has to be Java. This is why:



I'm working with a client who's in the UMTS business. I have to create for him two different sites that will be accesible on one domainname. So I have to use a redirect script.



The problem is these UMTS phones only support Java and HTML. So I have to use Java to redirect the user to the right website.



So, when a PC is visiting the website he will be directed to the big website and when a UMTS phone is visiting the website he will be directed to the small website.



So I need a Java applet that sais that when you are visiting the site with the IE or with Netscape you'll go to the big site, otherwise you'll go to the other site. What also would be good is that when you are visiting with a screen resolution less than 640 x 480 you go to the small site and otherwise you go to the bg site.



Several days now I'm looking on the internet for the right applet and I could not find it. I promised my client that I would implement such a Java redirect script so I really hope you guys can help me out.



Thanks! [/B]
[/QUOTE]
One way or the other the client hits this web site with a web browser. This detection and redirection must be done on the server side in order to eliminate the need for Javascript or Java applet capabilities on the browser. If your client brings this page up as a JSP running on Tomcat then my solution will work and it will be the cheapest, most robust way to satisfy your stated requirement. It will also keep them in their Java comfort zone although exactly the same thing could be accomplished by ANY server-side technology; PHP, ASP, CGI, etc.
Copy linkTweet thisAlerts:
@Frank1984authorSep 28.2004 — [i]Originally posted by ray326 [/i]

[B]It would look something like this:

<i>
</i>&lt;%
if (request.getHeader("user-agent").indexOf("MSIE") &gt; -1)
response.sendRedirect("pc/index.htm");
else if (request.getHeader("user-agent").indexOf("Firefox") &gt; -1)
response.sendRedirect("pc/index.htm");
else
response.sendRedirect("phone/index.htm");
%&gt;
[/B][/QUOTE]


So if my server support the stuff you mentioned above, then all I have to do is put the script above in the header of an html document and it should work.
Copy linkTweet thisAlerts:
@ray326Sep 29.2004 — Yea, any JSP should do for that. You can do it with any server-side technology; the ASP or PHP versions would look very little different. It just depends what you've got available on that particular server. Since we're talking Java here that's why I did it with JSP.
×

Success!

Help @Frank1984 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.16,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...