You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by DEVAL SHAH <de...@hotmail.com> on 2007/01/05 07:58:24 UTC

Apache+Tomcat+mod_jk+cookie+Rewrite

Hello,
I notice that because of url rewriting [RewriteRule] my cookie is not being 
passed to Tomcat. This is what I am doing:
I have mod_jk as connector between Tomcat and Apache.
I have an HTML page where I set my cookie - username.
Now If I call the servlet directly from html page then cookie gets passed 
e.g. /MyApp/MyServlet it works well.
But I have added a redirection as follows:

RewriteRule ^/url1$ /MyApp/MyServlet     [PT]

MyApp is a web application in Tomcat.
Now in my HTML page in the onSubmit function I call /url1 instead of servlet 
directly - this redirects to the servlet but the cookie is not set.

How do i go about passing the cookie to the servlet using RewriteRule ?

Thank you in advance
Deval



---------------------------------------------------------------------
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: Apache+Tomcat+mod_jk+cookie+Rewrite

Posted by Peter Rossbach <pr...@objektpark.de>.
Right, is the url at same domain you can use emptySessionPath at your  
connector configuration.

<Connector emptysessionPath="true" ... />

Docs say:

set to true, all paths for session cookies will be set to /. This can  
be useful for portlet specification implementations, but will greatly  
affect performance if many applications are accessed on a given  
server by the client. If not specified, this attribute is set to false.


Regards
Peter

Am 05.01.2007 um 15:29 schrieb Christopher Schultz:

> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> Deval,
>
> DEVAL SHAH wrote:
>> I notice that because of url rewriting [RewriteRule] my cookie is not
>> being passed to Tomcat.
>
> It's not your rewrite rule that is dropping your cookie. It's the fact
> that you are changing the path of the URI.
>
>> RewriteRule ^/url1$ /MyApp/MyServlet     [PT]
>
> I'm guessing that your webapp emits a cookie with the path of "/ 
> MyApp".
> If your app also emits URLs of the form http://whatever/url1/ 
> MyServlet,
> then the browser will not send the cookie along with the request
> (because the cookie belongs to /MyApp, not /url1).
>
> You can probably verify this using a packet sniffer or a much more
> convenient tool like LiveHttpHeaders for Mozilla Firefox or perhaps a
> plug-in for MSIE or another browser.
>
>> How do i go about passing the cookie to the servlet using  
>> RewriteRule ?
>
> You will need to do one of several things:
>
> 1. Stop using this other URL.
> 2. Move that URL-to-be-re-written inside the URL space of your
>    webapp (i.e. change /url1 to /MyApp/url1).
> 3. Modify your cookie configuration such that the path will be set
>    to "/" instead of "/MyApp" (I think single-sign-op will do this,
>    but there are probably other ways, too).
> 4. Use javascript to mutate the cookie and send (another copy) to
>    the browser with the path of "/url1" (you're already using  
> javascript
>    in your onsubmit event handler, so this should always work).
>
> I highly recommend #2. It's pretty easy, and you don't have to  
> resort to
> any hacks in your application to make it work (other than the obvious
> hack of using mod_rewrite in the first place).
>
> - -chris
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.6 (MingW32)
> Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
>
> iD8DBQFFnmC59CaO5/Lv0PARAl+YAKCy7JXb2gmrG7Yv1jMRvlrXMqvmMACgoCEc
> F9aJLnjBWwGCAJAkMdN01fU=
> =A2S+
> -----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
>
>


Re: Apache+Tomcat+mod_jk+cookie+Rewrite

Posted by DEVAL SHAH <de...@hotmail.com>.
Hello Christopher,
Thanks for the help. I used your option #3 and it is working. I could not 
use 2nd option as the requirement is to use /url1.
I set the cookie path "/" and it works fine now.

Thank you.


>From: Christopher Schultz <ch...@christopherschultz.net>
>Reply-To: "Tomcat Users List" <us...@tomcat.apache.org>
>To: Tomcat Users List <us...@tomcat.apache.org>
>Subject: Re: Apache+Tomcat+mod_jk+cookie+Rewrite
>Date: Fri, 05 Jan 2007 09:29:13 -0500
>
>-----BEGIN PGP SIGNED MESSAGE-----
>Hash: SHA1
>
>Deval,
>
>DEVAL SHAH wrote:
> > I notice that because of url rewriting [RewriteRule] my cookie is not
> > being passed to Tomcat.
>
>It's not your rewrite rule that is dropping your cookie. It's the fact
>that you are changing the path of the URI.
>
> > RewriteRule ^/url1$ /MyApp/MyServlet     [PT]
>
>I'm guessing that your webapp emits a cookie with the path of "/MyApp".
>If your app also emits URLs of the form http://whatever/url1/MyServlet,
>then the browser will not send the cookie along with the request
>(because the cookie belongs to /MyApp, not /url1).
>
>You can probably verify this using a packet sniffer or a much more
>convenient tool like LiveHttpHeaders for Mozilla Firefox or perhaps a
>plug-in for MSIE or another browser.
>
> > How do i go about passing the cookie to the servlet using RewriteRule ?
>
>You will need to do one of several things:
>
>1. Stop using this other URL.
>2. Move that URL-to-be-re-written inside the URL space of your
>    webapp (i.e. change /url1 to /MyApp/url1).
>3. Modify your cookie configuration such that the path will be set
>    to "/" instead of "/MyApp" (I think single-sign-op will do this,
>    but there are probably other ways, too).
>4. Use javascript to mutate the cookie and send (another copy) to
>    the browser with the path of "/url1" (you're already using javascript
>    in your onsubmit event handler, so this should always work).
>
>I highly recommend #2. It's pretty easy, and you don't have to resort to
>any hacks in your application to make it work (other than the obvious
>hack of using mod_rewrite in the first place).
>
>- -chris
>-----BEGIN PGP SIGNATURE-----
>Version: GnuPG v1.4.6 (MingW32)
>Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
>
>iD8DBQFFnmC59CaO5/Lv0PARAl+YAKCy7JXb2gmrG7Yv1jMRvlrXMqvmMACgoCEc
>F9aJLnjBWwGCAJAkMdN01fU=
>=A2S+
>-----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
>



---------------------------------------------------------------------
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: Apache+Tomcat+mod_jk+cookie+Rewrite

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

Deval,

DEVAL SHAH wrote:
> I notice that because of url rewriting [RewriteRule] my cookie is not
> being passed to Tomcat.

It's not your rewrite rule that is dropping your cookie. It's the fact
that you are changing the path of the URI.

> RewriteRule ^/url1$ /MyApp/MyServlet     [PT]

I'm guessing that your webapp emits a cookie with the path of "/MyApp".
If your app also emits URLs of the form http://whatever/url1/MyServlet,
then the browser will not send the cookie along with the request
(because the cookie belongs to /MyApp, not /url1).

You can probably verify this using a packet sniffer or a much more
convenient tool like LiveHttpHeaders for Mozilla Firefox or perhaps a
plug-in for MSIE or another browser.

> How do i go about passing the cookie to the servlet using RewriteRule ?

You will need to do one of several things:

1. Stop using this other URL.
2. Move that URL-to-be-re-written inside the URL space of your
   webapp (i.e. change /url1 to /MyApp/url1).
3. Modify your cookie configuration such that the path will be set
   to "/" instead of "/MyApp" (I think single-sign-op will do this,
   but there are probably other ways, too).
4. Use javascript to mutate the cookie and send (another copy) to
   the browser with the path of "/url1" (you're already using javascript
   in your onsubmit event handler, so this should always work).

I highly recommend #2. It's pretty easy, and you don't have to resort to
any hacks in your application to make it work (other than the obvious
hack of using mod_rewrite in the first place).

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

iD8DBQFFnmC59CaO5/Lv0PARAl+YAKCy7JXb2gmrG7Yv1jMRvlrXMqvmMACgoCEc
F9aJLnjBWwGCAJAkMdN01fU=
=A2S+
-----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