You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Eric Rank <er...@lo-fi.net> on 2007/03/05 21:00:09 UTC

Non standard url parameter -- when jsessionid appended

Happy Monday everyone. I have a question for you. Hopefully it  
doesn't go too far off track.

When I'm using the struts url tag (struts 2) to generate a link, I  
get a non standard url parameter, ";jsessionid" appended on the first  
visit with a new browser session. It seems that this occurs with a  
call to the HttpServletResponse.encodeURL method.

I get a URL like this (note the semicolon):

/context/namespace/page.action;jsessionid=xxxx

instead of what I would hope for (question mark replaces the semicolon):

/context/namespace/page.action?jsessionid=xxxx

The real problem occurs when I attempt to serve the page through  
Apache httpd and mod_jk (running on a httpd / mod_jk / tomcat  
environment). I'm guessing that Apache httpd sees the request as a  
type of ".action;jsessionid=xxxxxxx"  instead if a type ".action" and  
serves the resulting content (rendered correctly by tomcat) as plain  
text. The ".action" type has been added to the httpd.conf with the  
addType directive. All of the session stuff is handled normally with  
tomcat.

The question:

Ultimately, how can I get Apache httpd to display the content as  
"text/html" when I have a "jsessionid" appended to urls?

Is there something I can configure with httpd.conf?
Is there something I can configure with web.xml?
Is there a way to make the call to the HttpServletResponse.encodeURL  
use a question mark instead of a semicolon?

Thanks for your help!

Eric Rank

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Non standard url parameter -- when jsessionid appended [SOLVED]

Posted by Eric Rank <er...@lo-fi.net>.
Thanks Chris,

You're right! I did run into that exact same problem. I can add a  
third solution to the ones you offer. The struts 2 url tag has an  
"encode" attribute. When you do:

<s:url value="mycssFile.css" encode="false" id="link" />
<link href="${link}" type="text/css" rel="stylesheet" />

The jsessionid is omitted from the generated path. However, this  
should be used with care, because it removes all encoding. However  
for css, image, js, and other external files, that shouldn't be a  
problem.

Eric.

On Mar 5, 2007, at 3:54 PM, Christopher Schultz wrote:

> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> Eric,
>
> Eric Rank wrote:
>> Solved this problem.
>>
>> By setting the DefaultType directive to "text/html" in Apache's
>> httpd.conf, the pages with urls containing the appended ";jsessionid"
>> display as html, not plain text.
>>
>> I should have thought of that before :-)
>
> Since you ran across this problem, you are likely to run across  
> another
> one with url-encoded parameters and Apache httpd out in front of  
> Tomcat:
> if you want Apache httpd to serve a static file (say, a CSS file or an
> image), the ";jsessionid=..." part is treated as part of the filename
> (which will never be found).
>
> There are two ways that I know to fix this so that Apache httpd can
> still serve encoded URLs:
>
> 1. Use mod_rewrite with this rule:
>
> RewriteRule /myapp/(.*);jsessionid=[0-9A-Z]*(.*) /path/to/myapp/$1 
> $2 [L]
>
> If your app is deployed as the root, then remove "/myapp" from  
> those URLs.
>
> 2. Use "JkStripSession On" in your httpd.conf file. This is a new
>    feature of the as-yet-unreleased mod_jk 1.2.21.
>
> I used to use #1 and now I will use #2 because it is more
> straightforward and allows me to disable mod_rewrite in my server.
>
> Hope that helps,
> - -chris
>
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.6 (MingW32)
> Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
>
> iD8DBQFF7J+V9CaO5/Lv0PARAvTAAKCgCLbbSQCGQUxRBs11cdzkXsA2pwCeK74J
> I2ho+x9Etxwhyl0kkjJIbmY=
> =w9ZU
> -----END PGP SIGNATURE-----
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Non standard url parameter -- when jsessionid appended [SOLVED]

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

Eric,

Eric Rank wrote:
> Solved this problem.
> 
> By setting the DefaultType directive to "text/html" in Apache's
> httpd.conf, the pages with urls containing the appended ";jsessionid"
> display as html, not plain text.
> 
> I should have thought of that before :-)

Since you ran across this problem, you are likely to run across another
one with url-encoded parameters and Apache httpd out in front of Tomcat:
if you want Apache httpd to serve a static file (say, a CSS file or an
image), the ";jsessionid=..." part is treated as part of the filename
(which will never be found).

There are two ways that I know to fix this so that Apache httpd can
still serve encoded URLs:

1. Use mod_rewrite with this rule:

RewriteRule /myapp/(.*);jsessionid=[0-9A-Z]*(.*) /path/to/myapp/$1$2 [L]

If your app is deployed as the root, then remove "/myapp" from those URLs.

2. Use "JkStripSession On" in your httpd.conf file. This is a new
   feature of the as-yet-unreleased mod_jk 1.2.21.

I used to use #1 and now I will use #2 because it is more
straightforward and allows me to disable mod_rewrite in my server.

Hope that helps,
- -chris

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

iD8DBQFF7J+V9CaO5/Lv0PARAvTAAKCgCLbbSQCGQUxRBs11cdzkXsA2pwCeK74J
I2ho+x9Etxwhyl0kkjJIbmY=
=w9ZU
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Non standard url parameter -- when jsessionid appended [SOLVED]

Posted by Eric Rank <er...@lo-fi.net>.
Solved this problem.

By setting the DefaultType directive to "text/html" in Apache's  
httpd.conf, the pages with urls containing the appended ";jsessionid"  
display as html, not plain text.

I should have thought of that before :-)

Thanks

Eric.


On Mar 5, 2007, at 2:32 PM, Eric Rank wrote:

> Thanks Michael,
>
> I was just reading up on the servlet spec and you're right, the  
> jsessionid is not a regular query parameter. Everything that's  
> happening is as according to spec.
>
> The redirection to the same page when the session cookie is set  
> would work, but only for those who have session cookies enabled.  
> For those who don't have cookies enabled, I suppose I'll need to  
> forward them to a page asking them to turn that feature on.
>
> ... If the web server would see the response output as text/html,  
> I'd be in business without any of that work. I think I might just  
> set the default type to text/html in the httpd.conf. Hmmm ... [goes  
> to try it out]
>
>
> Eric
>
>
>
>
>
>
>
> On Mar 5, 2007, at 2:19 PM, Michael Jouravlev wrote:
>
>> From servlet engine point of view, jsessionid is not a query
>> parameter, you can verify that by calling getParameter or
>> getParameterMap on request object, jsessionid is not there.
>>
>> To my mind, the simplest thing one can do is to get rid of jsessionid
>> parameter. To do this you need to have cookies enabled in the  
>> browser.
>> When you make the first request it will be free of session id. On
>> server check for session id cookie, if it is not in the request,
>> perform a redirect to the same URL. From this point on session id  
>> will
>> be passed as a cookie.
>>
>> Michael.
>>
>> On 3/5/07, Eric Rank <er...@lo-fi.net> wrote:
>>> Happy Monday everyone. I have a question for you. Hopefully it
>>> doesn't go too far off track.
>>>
>>> When I'm using the struts url tag (struts 2) to generate a link, I
>>> get a non standard url parameter, ";jsessionid" appended on the  
>>> first
>>> visit with a new browser session. It seems that this occurs with a
>>> call to the HttpServletResponse.encodeURL method.
>>>
>>> I get a URL like this (note the semicolon):
>>>
>>> /context/namespace/page.action;jsessionid=xxxx
>>>
>>> instead of what I would hope for (question mark replaces the  
>>> semicolon):
>>>
>>> /context/namespace/page.action?jsessionid=xxxx
>>>
>>> The real problem occurs when I attempt to serve the page through
>>> Apache httpd and mod_jk (running on a httpd / mod_jk / tomcat
>>> environment). I'm guessing that Apache httpd sees the request as a
>>> type of ".action;jsessionid=xxxxxxx"  instead if a type ".action"  
>>> and
>>> serves the resulting content (rendered correctly by tomcat) as plain
>>> text. The ".action" type has been added to the httpd.conf with the
>>> addType directive. All of the session stuff is handled normally with
>>> tomcat.
>>>
>>> The question:
>>>
>>> Ultimately, how can I get Apache httpd to display the content as
>>> "text/html" when I have a "jsessionid" appended to urls?
>>>
>>> Is there something I can configure with httpd.conf?
>>> Is there something I can configure with web.xml?
>>> Is there a way to make the call to the HttpServletResponse.encodeURL
>>> use a question mark instead of a semicolon?
>>>
>>> Thanks for your help!
>>>
>>> Eric Rank
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>> For additional commands, e-mail: user-help@struts.apache.org
>>
>


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Non standard url parameter -- when jsessionid appended

Posted by Eric Rank <er...@lo-fi.net>.
Thanks Michael,

I was just reading up on the servlet spec and you're right, the  
jsessionid is not a regular query parameter. Everything that's  
happening is as according to spec.

The redirection to the same page when the session cookie is set would  
work, but only for those who have session cookies enabled. For those  
who don't have cookies enabled, I suppose I'll need to forward them  
to a page asking them to turn that feature on.

... If the web server would see the response output as text/html, I'd  
be in business without any of that work. I think I might just set the  
default type to text/html in the httpd.conf. Hmmm ... [goes to try it  
out]


Eric







On Mar 5, 2007, at 2:19 PM, Michael Jouravlev wrote:

> From servlet engine point of view, jsessionid is not a query
> parameter, you can verify that by calling getParameter or
> getParameterMap on request object, jsessionid is not there.
>
> To my mind, the simplest thing one can do is to get rid of jsessionid
> parameter. To do this you need to have cookies enabled in the browser.
> When you make the first request it will be free of session id. On
> server check for session id cookie, if it is not in the request,
> perform a redirect to the same URL. From this point on session id will
> be passed as a cookie.
>
> Michael.
>
> On 3/5/07, Eric Rank <er...@lo-fi.net> wrote:
>> Happy Monday everyone. I have a question for you. Hopefully it
>> doesn't go too far off track.
>>
>> When I'm using the struts url tag (struts 2) to generate a link, I
>> get a non standard url parameter, ";jsessionid" appended on the first
>> visit with a new browser session. It seems that this occurs with a
>> call to the HttpServletResponse.encodeURL method.
>>
>> I get a URL like this (note the semicolon):
>>
>> /context/namespace/page.action;jsessionid=xxxx
>>
>> instead of what I would hope for (question mark replaces the  
>> semicolon):
>>
>> /context/namespace/page.action?jsessionid=xxxx
>>
>> The real problem occurs when I attempt to serve the page through
>> Apache httpd and mod_jk (running on a httpd / mod_jk / tomcat
>> environment). I'm guessing that Apache httpd sees the request as a
>> type of ".action;jsessionid=xxxxxxx"  instead if a type ".action" and
>> serves the resulting content (rendered correctly by tomcat) as plain
>> text. The ".action" type has been added to the httpd.conf with the
>> addType directive. All of the session stuff is handled normally with
>> tomcat.
>>
>> The question:
>>
>> Ultimately, how can I get Apache httpd to display the content as
>> "text/html" when I have a "jsessionid" appended to urls?
>>
>> Is there something I can configure with httpd.conf?
>> Is there something I can configure with web.xml?
>> Is there a way to make the call to the HttpServletResponse.encodeURL
>> use a question mark instead of a semicolon?
>>
>> Thanks for your help!
>>
>> Eric Rank
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Non standard url parameter -- when jsessionid appended

Posted by Michael Jouravlev <jm...@gmail.com>.
>From servlet engine point of view, jsessionid is not a query
parameter, you can verify that by calling getParameter or
getParameterMap on request object, jsessionid is not there.

To my mind, the simplest thing one can do is to get rid of jsessionid
parameter. To do this you need to have cookies enabled in the browser.
When you make the first request it will be free of session id. On
server check for session id cookie, if it is not in the request,
perform a redirect to the same URL. From this point on session id will
be passed as a cookie.

Michael.

On 3/5/07, Eric Rank <er...@lo-fi.net> wrote:
> Happy Monday everyone. I have a question for you. Hopefully it
> doesn't go too far off track.
>
> When I'm using the struts url tag (struts 2) to generate a link, I
> get a non standard url parameter, ";jsessionid" appended on the first
> visit with a new browser session. It seems that this occurs with a
> call to the HttpServletResponse.encodeURL method.
>
> I get a URL like this (note the semicolon):
>
> /context/namespace/page.action;jsessionid=xxxx
>
> instead of what I would hope for (question mark replaces the semicolon):
>
> /context/namespace/page.action?jsessionid=xxxx
>
> The real problem occurs when I attempt to serve the page through
> Apache httpd and mod_jk (running on a httpd / mod_jk / tomcat
> environment). I'm guessing that Apache httpd sees the request as a
> type of ".action;jsessionid=xxxxxxx"  instead if a type ".action" and
> serves the resulting content (rendered correctly by tomcat) as plain
> text. The ".action" type has been added to the httpd.conf with the
> addType directive. All of the session stuff is handled normally with
> tomcat.
>
> The question:
>
> Ultimately, how can I get Apache httpd to display the content as
> "text/html" when I have a "jsessionid" appended to urls?
>
> Is there something I can configure with httpd.conf?
> Is there something I can configure with web.xml?
> Is there a way to make the call to the HttpServletResponse.encodeURL
> use a question mark instead of a semicolon?
>
> Thanks for your help!
>
> Eric Rank

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org