wood burning stoves 2.0*
The moose likes HTML, CSS and JavaScript and the fly likes Redirect when Javascript is disabled Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Redirect when Javascript is disabled" Watch "Redirect when Javascript is disabled" New topic
Author

Redirect when Javascript is disabled

Neeraj Vij
Ranch Hand

Joined: Nov 25, 2003
Posts: 315
Hi,

I need to redirect a user to different page from my homepage jsp to a different jsp page. How can I implement it. Please help.

Thanks,
Neeraj.
[ June 23, 2006: Message edited by: Bear Bibeault ]
Neeraj Vij
Ranch Hand

Joined: Nov 25, 2003
Posts: 315
sorry I forgot to add -when the javascript is disabled for the browser, I need to redirect.

Thanks
Neeraj.
Srilakshmi Vara
Ranch Hand

Joined: Jul 21, 2004
Posts: 169
If it is on a user event you can't capture an event with out using javascript, but with javascript can redirect very easily
Travis Hein
Ranch Hand

Joined: Jun 06, 2006
Posts: 161
when the process flow is
user activity -> server side (jsp / servlet handler) (redirect here) -> result page

then one can do a redirect before the resulting page is returned to the user with
response.sendRedirect() if there has not been any output rendered before the call to this for the response.
or the request.getDispatcher("./redirectPage").forward(request,response) type pattern if you are doing the redirect in the server side from within a jsp page after there has already been output, such as within a tiles templated panel.


otherwise if the flow is
user activity -> server side -> result page -> redirect using javascript

then when javascript is disabled, in this situation there is no server side involvement, the best way is to render a manual link within the noscript tag:


Error: Keyboard not attached. Press F1 to continue.
Neeraj Vij
Ranch Hand

Joined: Nov 25, 2003
Posts: 315
thanks for the inputs..

I have to follow the second approach..

I have to redirect user automatically.. I cannot use the

<noscript>
response.sendRedirect()
</noscript>

this works when javascript is off.. but this code is also executed when javascript is on

Please suggest something..

Thanks,
Neeraj
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60822
    
  65

Originally posted by Neeraj Vij:

<noscript>
response.sendRedirect()
</noscript>

this works when javascript is off.. but this code is also executed when javascript is on


Of course it executes. JSP code on the server has absolutely nothing to do with Javascript on the client, or any HTML markup for that matter.

The fact that redirect code in the above is inside a <noscript> block is completely irrelevant.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60822
    
  65

Originally posted by Neeraj Vij:
sorry I forgot to add -when the javascript is disabled for the browser, I need to redirect.


Can't be done.

No amount of JSP will help you since there is no way for JSP to detect whether Javascript is enabled before the page is even sent to the browser.

And without Javascript, you can't perform any activity on the client side.

Best you can do is to present a button or link to the user (using <noscript>) so that they can initiate the transfer to another page.

Or you can take the approach I frequently take: display "turn on Javascripr or go somewhere else". Of course, I say it a bit nicer than that, but the message is the same.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60822
    
  65

Another thought, would embedding a redirect meta tag in <noscript> work? It seems odd and something I would never do, but...

In any case, I'm moving this to the HTML forum since there is no JSP issue here.

I also changed the title to be more appropriate.
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
Here is an idea: REDIRECT THE JAVASCRIPT USER! If the user does not support JavaScript than they will remain on that page!!

Eric
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Redirect when Javascript is disabled
 
Similar Threads
frames help
Servlet Thread Communication ...Urgent
forwarding to jsp
Redirecting to a Page outside the web project
Defining error page