Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Redirect when Javascript is disabled

 
Neeraj Vij
Ranch Hand
Posts: 315
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 315
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sorry I forgot to add -when the javascript is disabled for the browser, I need to redirect.

Thanks
Neeraj.
 
Srilakshmi Vara
Ranch Hand
Posts: 169
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 161
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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:
 
Neeraj Vij
Ranch Hand
Posts: 315
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64843
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64843
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64843
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is an idea: REDIRECT THE JAVASCRIPT USER! If the user does not support JavaScript than they will remain on that page!!

Eric
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic