This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Servlets and the fly likes response.sendRedirect Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "response.sendRedirect" Watch "response.sendRedirect" New topic
Author

response.sendRedirect

Miran Cvenkel
Ranch Hand

Joined: Nov 23, 2010
Posts: 147
The point beeing, I renamed a.jsp to b.jsp, and want google to find it anyway.

in jsp



in JspStart



1. If I said redirect, why there must be return after that ? (othervise programm goes down executing things)
2. The first redirect that occurs in that manner --> java emidiately starts eating 100% CPU and it does not let go, luckely multicore processor, so it does not hang ?

Searchable nature photo gallery: http://agrozoo.net/jsp/Galery.jsp?l2=en
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60800
    
  65

1. If you are going to redirect, it doesn't make any sense to continue emitting output that will never be seen.

2. Use a profiler tool to find out where your performance issue is.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

1. It's a basic rule of the Java language. Statements are executed one after the other. So when control returns from the sendRedirect() method, it continues on to the next statement.
Deepak Bala
Bartender

Joined: Feb 24, 2006
Posts: 6661
    
    5

The first redirect that occurs in that manner --> java emidiately starts eating 100% CPU and it does not let go, luckely multicore processor, so it does not hang ?


It is only a matter of time before all cores are consumed.

It looks like what you want is to rather send a HTTP 301 / 302 response status code ? Have you looked into that ?


SCJP 6 articles - SCJP 5/6 mock exams - More SCJP Mocks
Miran Cvenkel
Ranch Hand

Joined: Nov 23, 2010
Posts: 147
so if I go with last advice:

example: http://agrozoo.net/jsp/Tools.jsp?p0=Thesaurus&p3=67008d1cb23311df864f001cc081f832
is redirected to new adress with this code:



it works but this tester http://www.webconfs.com/redirect-check.php says it is not OK.
Is it bad tester or I'm doing something wrong ?

Deepak Bala
Bartender

Joined: Feb 24, 2006
Posts: 6661
    
    5

Miran Cvenkel wrote:so if I go with last advice:

example: http://agrozoo.net/jsp/Tools.jsp?p0=Thesaurus&p3=67008d1cb23311df864f001cc081f832
is redirected to new adress with this code:



it works but this tester http://www.webconfs.com/redirect-check.php says it is not OK.
Is it bad tester or I'm doing something wrong ?



The tester probably tries to use your relative URL in the Location header and fails. SEO wise, I am not sure if that is good or bad. You can research that and make a decision.
Miran Cvenkel
Ranch Hand

Joined: Nov 23, 2010
Posts: 147


Missing return, now tester is happy. Thanks.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: response.sendRedirect
 
Similar Threads
Finding current URI?
Want to find out request is sent from which page
Using jsp:useBean across JSPs
pass the session variable to 2 jsp simultaneously
How to open new page and open behind.