File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Other Open Source Projects and the fly likes How do I redirect to a specific URL? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Products » Other Open Source Projects
Bookmark "How do I redirect to a specific URL?" Watch "How do I redirect to a specific URL?" New topic

How do I redirect to a specific URL?

Joe Kang

Joined: Oct 06, 2010
Posts: 2
I am running a Java application using Tomcat 6 and JBoss 5.1. I've created an URL redirection function using Java Elements addHtml() function (javascript). Well, I am able to alert the URL of current browser (alert(window.location.href)) but I am not able to redirect to a specific URL (window.location.href = 'URL'). The code shown as below:

At the same time, the IE status bar is processing but somehow it does not redirect me to the page. Help needed. Thanks in advance =)
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63870

What is "Java Elements"?

[Asking smart questions] [About Bear] [Books by Bear]
Joe Kang

Joined: Oct 06, 2010
Posts: 2 Here you go
Martijn Verburg

Joined: Jun 24, 2003
Posts: 3275

And welcome to Javaranch Joe!

Cheers, Martijn - Blog,
Twitter, PCGen, Ikasan, My The Well-Grounded Java Developer book!,
My start-up.
Paul Clapham

Joined: Oct 14, 2005
Posts: 19973

Joe Kang wrote: Here you go

Okay, I'm lost. So now I understand that the code you posted is Java code. Or so you say. However the documentation you linked to is confusing, because in your code the Element object has an addHtml() method and in that documentation, it doesn't.

But anyway, what are you trying to do? If you want to redirect to some other URL from that Java code, then generating Javascript code is pointless. And generating a DOM which contains that Javascript is just as pointless. Just call the response object's sendRedirect(URL) method.

Or were you hoping the Javascript code could somehow redirect to the URL? If you somehow managed to get it into the browser, that is? You remark about IE's status bar pointing to is also baffling because if the browser sent a request to that URL then your code wouldn't be running.

So I would suggest you go back a couple of steps and try to explain all of this.
I agree. Here's the link:
subject: How do I redirect to a specific URL?
It's not a secret anymore!