You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by ashwin soorkeea <cv...@hotmail.com> on 2007/12/16 15:19:06 UTC

Response.SendRedirect problems

Hello all,
 
I have a problem for my application and this prob is causing an entire netw=
ork of users from using my application. I will appreciate
if you guys can help me solve my prob.
 
It concerns the servlet response.sendRedirect(...) method.
 
When using the response.sendRedirect("/myexample") in my java class, i do n=
ot want the servlet engine to reconstruct
an absolute URL, before sending the response to the browser. I want it to b=
e handle by the browser keeping it relative throughout
the application. I know it's possible, but i dunno how to do it. Can you he=
lp ?=20
 
The URL reconstruction by the servlet engine during a redirection is causin=
g some problems in my application.
 
Example:
I have this link on browser http://127.0.0.1:<port_number>, when performing=
 a sendRedirect, i'm losing the <port_number>
during the url reconstruction by the servlet engine.
On the other hand, i have another application that is interconnected, but i=
n this application, the url is relative throughout, even though
it passes through the response.sendRedirect(...) and consequently, i do not=
 have this prob in this application.
 
Im using tomcat-4.1 and i'm checking the URL redirection using the HTTP liv=
e header plugins for firefox.
 
Thank you for your help.
Regards,
Ashwin
_________________________________________________________________
i’m is proud to present Cause Effect, a series about real people making a difference.
http://im.live.com/Messenger/IM/MTV/?source=text_Cause_Effect

Re: Response.SendRedirect problems

Posted by david delbecq <de...@oma.be>.
ashwin soorkeea a écrit :
> Hello all,
>  
> I have a problem for my application and this prob is causing an entire netw=
> ork of users from using my application. I will appreciate
> if you guys can help me solve my prob.
>  
> It concerns the servlet response.sendRedirect(...) method.
>  
> When using the response.sendRedirect("/myexample") in my java class, i do n=
> ot want the servlet engine to reconstruct
> an absolute URL, before sending the response to the browser. I want it to b=
> e handle by the browser keeping it relative throughout
> the application. I know it's possible, but i dunno how to do it. Can you he=
> lp ?=20
>   
If you use sendRedirect, it's not possible:


      sendRedirect

public void *sendRedirect*(java.lang.String location)
                  throws java.io.IOException

Sends a temporary redirect response to the client using the specified 
redirect location URL. This method can accept relative URLs; the servlet 
container _must convert the relative URL to an absolute URL before 
sending the response to the client_. If the location is relative without 
a leading '/' the container interprets it as relative to the current 
request URI. If the location is relative with a leading '/' the 
container interprets it as relative to the servlet container root.
>  
> The URL reconstruction by the servlet engine during a redirection is causin=
> g some problems in my application.
>   
It shouldn't unless either application or tomcat has bugs. :)
>  
> Example:
> I have this link on browser http://127.0.0.1:<port_number>, when performing=
>  a sendRedirect, i'm losing the <port_number>
> during the url reconstruction by the servlet engine.
>   
That's probably because tomcat is not aware, for various reason, of the 
correct port number (behind a proxy or apache for example). You can 
specify in tomcat configuration which port number to use when 
reconstructing urls:
http://tomcat.apache.org/tomcat-4.1-doc/config/http11.html   (see 
'redirectPort')

> On the other hand, i have another application that is interconnected, but i=
> n this application, the url is relative throughout, even though
> it passes through the response.sendRedirect(...) and consequently, i do not=
>  have this prob in this application.
>   
If it's relative, it's not using sendRedirect , but it's setting by 
itself the response header (response.addHeader() )
>  
> Im using tomcat-4.1 and i'm checking the URL redirection using the HTTP liv=
> e header plugins for firefox.
>   
Maybe try to upgrade? ;)


---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Response.SendRedirect problems

Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Konstantin,

On 2/25/2011 4:11 AM, Konstantin Kolinko wrote:
>>> It concerns the servlet response.sendRedirect(...) method.
>>>
>>> When using the response.sendRedirect("/myexample") in my java class, i do
>>> n=
>>> ot want the servlet engine to reconstruct
>>> an absolute URL, before sending the response to the browser.
> 
> That is not possible, because of how HTTP spec is written.

It's probably not possible using response.sendRedirect, but it should be
possible using response.setStatus(302) (or whatever response code you
want) and response.setHeader("Location", "/myexample").

Note that this violates the HTTP spec
(http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.30) which
says that the Location response header is fully-qualified.

>> On redirection the port number is getting omitted
> 
> You should describe your configuration in detail first.  Though I
> think you miss "proxyPort" attribute on a connector.  (IIRC, it should
> not be necessary for AJP though).

Faheem, you can't have a relative "Location" that includes a port
number: that will require an absolute (fully-qualified) URI. If Tomcat
is incorrectly (or not at all) inserting the port number into the
Location field, please let me know.

- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAk1oAJoACgkQ9CaO5/Lv0PDgLQCfQC5cFLCkNogWKxQeuldECaQk
+wUAn06iE5pAYxhKA8Nj7eKh3HFbP8BO
=ZMum
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Response.SendRedirect problems

Posted by Konstantin Kolinko <kn...@gmail.com>.
>> It concerns the servlet response.sendRedirect(...) method.
>>
>> When using the response.sendRedirect("/myexample") in my java class, i do
>> n=
>> ot want the servlet engine to reconstruct
>> an absolute URL, before sending the response to the browser.

That is not possible, because of how HTTP spec is written.

> On redirection the port number is
> getting omitted

You should describe your configuration in detail first.  Though I
think you miss "proxyPort" attribute on a connector.  (IIRC, it should
not be necessary for AJP though).


2011/2/24 faheem farhan <fa...@gmail.com>:
>
> Hi Ashwin
>
> I am too facing the same issue now , On redirection the port number is
> getting omitted, Since this is a 2 years back thread, I suppose you might
> have got the solution, Please reply back with the solution.
>
> thanks
> faheem
>
>
>
> ashwin soorkeea wrote:
>>
>>
>> Hello all,
>>
>> I have a problem for my application and this prob is causing an entire
>> netw=
>> ork of users from using my application. I will appreciate
>> if you guys can help me solve my prob.
>>
>> It concerns the servlet response.sendRedirect(...) method.
>>
>> When using the response.sendRedirect("/myexample") in my java class, i do
>> n=
>> ot want the servlet engine to reconstruct
>> an absolute URL, before sending the response to the browser. I want it to
>> b=
>> e handle by the browser keeping it relative throughout
>> the application. I know it's possible, but i dunno how to do it. Can you
>> he=
>> lp ?=20
>>
>> The URL reconstruction by the servlet engine during a redirection is
>> causin=
>> g some problems in my application.
>>
>> Example:
>> I have this link on browser http://127.0.0.1:<port_number>, when
>> performing=
>>  a sendRedirect, i'm losing the <port_number>
>> during the url reconstruction by the servlet engine.
>> On the other hand, i have another application that is interconnected, but
>> i=
>> n this application, the url is relative throughout, even though
>> it passes through the response.sendRedirect(...) and consequently, i do
>> not=
>>  have this prob in this application.
>>
>> Im using tomcat-4.1 and i'm checking the URL redirection using the HTTP
>> liv=
>> e header plugins for firefox.
>>
>> Thank you for your help.
>> Regards,
>> Ashwin
>> _________________________________________________________________
>> i’m is proud to present Cause Effect, a series about real people making a
>> difference.
>> http://im.live.com/Messenger/IM/MTV/?source=text_Cause_Effect
>>
>
> --
> View this message in context: http://old.nabble.com/Response.SendRedirect-problems-tp14361975p31005032.html
> Sent from the Tomcat - User mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Response.SendRedirect problems

Posted by faheem farhan <fa...@gmail.com>.
Hi Ashwin

I am too facing the same issue now , On redirection the port number is
getting omitted, Since this is a 2 years back thread, I suppose you might
have got the solution, Please reply back with the solution.

thanks
faheem



ashwin soorkeea wrote:
> 
> 
> Hello all,
>  
> I have a problem for my application and this prob is causing an entire
> netw=
> ork of users from using my application. I will appreciate
> if you guys can help me solve my prob.
>  
> It concerns the servlet response.sendRedirect(...) method.
>  
> When using the response.sendRedirect("/myexample") in my java class, i do
> n=
> ot want the servlet engine to reconstruct
> an absolute URL, before sending the response to the browser. I want it to
> b=
> e handle by the browser keeping it relative throughout
> the application. I know it's possible, but i dunno how to do it. Can you
> he=
> lp ?=20
>  
> The URL reconstruction by the servlet engine during a redirection is
> causin=
> g some problems in my application.
>  
> Example:
> I have this link on browser http://127.0.0.1:<port_number>, when
> performing=
>  a sendRedirect, i'm losing the <port_number>
> during the url reconstruction by the servlet engine.
> On the other hand, i have another application that is interconnected, but
> i=
> n this application, the url is relative throughout, even though
> it passes through the response.sendRedirect(...) and consequently, i do
> not=
>  have this prob in this application.
>  
> Im using tomcat-4.1 and i'm checking the URL redirection using the HTTP
> liv=
> e header plugins for firefox.
>  
> Thank you for your help.
> Regards,
> Ashwin
> _________________________________________________________________
> i’m is proud to present Cause Effect, a series about real people making a
> difference.
> http://im.live.com/Messenger/IM/MTV/?source=text_Cause_Effect
> 

-- 
View this message in context: http://old.nabble.com/Response.SendRedirect-problems-tp14361975p31005032.html
Sent from the Tomcat - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Response.SendRedirect problems

Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Askwin,

ashwin soorkeea wrote:
> When using the response.sendRedirect("/myexample") in my java class,
> i do not want the servlet engine to reconstruct an absolute URL,
> before sending the response to the browser.

This request violates the servlet specification. From the 2.4 spec:

"SRV.5.3 Convenience Methods

The following convenience methods exist in the HttpServletResponse
interface:

• sendRedirect
• sendError

The sendRedirect method will set the appropriate headers and content
body to redirect the client to a different URL. It is legal to call this
method with a relative URL path, however the underlying container must
translate the relative path to a fully qualified URL for transmission
back to the client. If a partial URL is given and, for whatever reason,
cannot be converted into a valid URL, then this method must throw an
IllegalArgumentException.
"

> I want it to be [handled] by the browser keeping it relative throughout
> the application. I know it's possible, but i dunno how to do it. Can you help?

Why do you care? The browser needs an absolute URL to contact the
server, anyway, so it shouldn't matter.

Let me guess... you want to use URLs like "../somewhere/else" all over
the place. This is a management headache. It's much better to root
everything in "contextPath + relativeURL", especially because that's how
/everybody/ does it, and it's compatible with the servlet specification.

> Example:
> I have this link on browser http://127.0.0.1:<port_number>, when
> performing= a sendRedirect, i'm losing the <port_number> during the
> url reconstruction by the servlet engine.

Really? Can you post a servlet or JSP that fails in this way?

- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.7 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFHZcYw9CaO5/Lv0PARAkYtAJ9GTMtUfh/SW/eSPp/eywG95U4OXQCfWokc
hCU05p3hc4Mx8Q9AlX1jlN4=
=B4HL
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org