You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Ramez Ghazzaoui <ra...@alum.american.edu> on 2007/02/19 21:44:16 UTC

request.getParameter() in JSP misinterpreting foreign characters

Hi,

Back in May 2006, I had trouble Configuring Tomcat HTTP server to 
generate proper links for non-English file names in a Directory Listing. 
Mr. Mark Thomas proposed a solution that worked: He told me to set 
URIEncoding="UTF-8" in the connector (presumably in server.xml).

This fixed the Directory Listing problem, but ...

Today I realized that this very solution has broken the Java 
request.getParameter() method in JSP. Now, with the URIEncoding set to 
UTF-8, this Java method is misinterpreting non-English characters. When 
I invoke from the browser the following address: 
http://localhost/main.jsp?path=olé (or the equivalent 
http://localhost/main.jsp?path=ol%E9) a call to 
request.getParameter("path") from within main.jsp returns ol? where the 
question mark is character number 65533. That's way off from 233 (which 
is the correct U-dec for eacute, or é).

When I remove the URIEncoding="UTF-8" attribute from my connector, 
request.getParameter("path") returns olé as expected, and the JSP works 
as intended. However, of course, this breaks directory listings as 
described in my 26 May 2006 posting titled "How do I configure Tomcast 
HTTP server to generate working links for French file names in Tomcat 
Directory Listing?".

Is there a way to make French characters work both in Directory Listings 
and in GET parameters?

Thanks,

-Ramez


---------------------------------------------------------------------
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: request.getParameter() in JSP misinterpreting foreign characters

Posted by Mark Thomas <ma...@apache.org>.
Ramez Ghazzaoui wrote:
> Is there a way to make French characters work both in Directory Listings
> and in GET parameters?

All your pages need to include the following at the start:
<%@ page pageEncoding="UTF-8" %>

The correct UTF-8 encoding for your request is:
http://localhost/main.jsp?path=ol%C3%A9

HTH,

Mark


---------------------------------------------------------------------
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: request.getParameter() in JSP misinterpreting foreign characters

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

Ramez,

Ramez Ghazzaoui wrote:
> Thank you guys. Sounds like I need to either write or find a method that
> converts strings to UTF-8. I'll try this tomorrow.

Generally, java.net.URLEncoder.encode(yourString, "UTF-8") will do this
for you quite well. No need to roll your own.

If you use a JSP tag library for building URLs or anything like that,
your taglib should be providing this capability already.

Hope that helps,
- -chris

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

iD8DBQFF23Va9CaO5/Lv0PARAiT4AKCNxxZjTGJk0QTUVTk8HB6iI+7TYQCfTL1y
nz5Q084x5AKQXDrGJzPFZR0=
=HTe7
-----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: request.getParameter() in JSP misinterpreting foreign characters

Posted by Ramez Ghazzaoui <ra...@alum.american.edu>.
Thank you guys. Sounds like I need to either write or find a method that 
converts strings to UTF-8. I'll try this tomorrow.

BTW I am not using HTML forms, just building URIs dynamically and 
sticking them into <a href=...> anchors. That's where the GET part comes 
into play :)

Cheers,

-Ramez

Markus Schönhaber wrote:
> Ramez Ghazzaoui wrote:
>
>   
>> Today I realized that this very solution has broken the Java
>> request.getParameter() method in JSP. Now, with the URIEncoding set to
>> UTF-8, this Java method is misinterpreting non-English characters. When
>> I invoke from the browser the following address:
>> http://localhost/main.jsp?path=olé (or the equivalent
>> http://localhost/main.jsp?path=ol%E9) a call to
>> request.getParameter("path") from within main.jsp returns ol? where the
>> question mark is character number 65533. That's way off from 233 (which
>> is the correct U-dec for eacute, or é).
>>     
>
> If you tell Tomcat that you'll provide URIs which are encoded in UTF-8 then do 
> as you said and provide UTF-8-encoded URIs. Your example above should 
> therefore look like
> http://localhost/main.jsp?path=ol%C3%A9
>
> If you're using HTML-forms with method="GET", set the accept-charset attribute of the form to UTF-8.
>   
>   

---------------------------------------------------------------------
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: Persisting Sessions to Database for Fault-Tolerance

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

Nathan,

Nathan Hook wrote:
> Because we have too and because I'm not a fan.  : )

I think Hassan was asking /why/ you are not a fan. I'm sure the
community would love to hear why the existing clustering is no good, in
an effort to make it better.

> Is adding a new session attribute listener that will write a Session to
> the database and using the combination of PersistentManager with a
> JDBCStore viable for doing fail over with Tomcat servers?

Er, was that a question?

I would think that if you were going to implement your own
SessionBindingListener that writes to the database, you wouldn't want to
bother using a PersistentManager with a JDBCStore.

IIRC, the PersistentManager exists to hibernate the session data during
a re-deploy or after idle time to just get it out of memory. If you are
always using the database to store your session information, then you
will always have a "hibernated" version of the session, so the
PersistentManager is not useful in that case.

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

iD8DBQFF35BF9CaO5/Lv0PARAjYtAJ4hOPCHOl81dudU+IUBNtH0GpdXdACfWLga
jp3Hofx5cTTR8gmiUdG8KqY=
=MV51
-----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: Persisting Sessions to Database for Fault-Tolerance

Posted by Nathan Hook <nh...@knowledgefactor.com>.
Because we have too and because I'm not a fan.  : )

Is adding a new session attribute listener that will write a Session to 
the database and using the combination of PersistentManager with a 
JDBCStore viable for doing fail over with Tomcat servers?

If not, then why not?

Thank you for your time and have a great weekend.



Hassan Schroeder wrote:
> On 2/20/07, Nathan Hook <nh...@knowledgefactor.com> wrote:
>
>> The company I am working for is trying to get our application to
>> "Enterprise Strength" and have been working on server failover issues.
>
>> As of right now I'm not a fan of the current clustering solution that is
>> offered by tomcat
>
> Because?
>


---------------------------------------------------------------------
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: Persisting Sessions to Database for Fault-Tolerance

Posted by Hassan Schroeder <ha...@gmail.com>.
On 2/20/07, Nathan Hook <nh...@knowledgefactor.com> wrote:

> The company I am working for is trying to get our application to
> "Enterprise Strength" and have been working on server failover issues.

> As of right now I'm not a fan of the current clustering solution that is
> offered by tomcat

Because?

-- 
Hassan Schroeder ------------------------ hassan.schroeder@gmail.com

---------------------------------------------------------------------
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


Persisting Sessions to Database for Fault-Tolerance

Posted by Nathan Hook <nh...@knowledgefactor.com>.
I posted this question/idea to a forum and received no responses.  I am 
hoping to get some thoughtful discussion/ideas from this mailing list...

The company I am working for is trying to get our application to 
"Enterprise Strength" and have been working on server failover issues. 
I've never had to solve a solution like this before and was hoping for 
some advice.

As of right now I'm not a fan of the current clustering solution that is 
offered by tomcat and have decided to try and use the 
PersistentManager/JDBCStore solution.

Please see the following link for an example:

http://www.ingrid.org/jajakarta/tomcat/tomcat-4.0b5/src/catalina/docs/JDBCStore-howto.html

Unfortunately, using the PersistentManager the HttpSession gets written 
to the database about 10 to 15 seconds after a new HttpSession gets created.

We wrote a custom HttpSessionAttributeListener that listens for the one 
attribute we actually store in our HttpSession and when we receive that 
event we persist the session to the Database.

Will this solution work for server failover for an Enterprise system?

I like the solution because in theory we don't have to ever worry about 
adding clustering to the server.xml and in theory we don't ever have to 
worry about bringing down a server or set of servers if we need to.

Thank you for your time.

---------------------------------------------------------------------
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: request.getParameter() in JSP misinterpreting foreign characters

Posted by Markus Schönhaber <ma...@schoenhaber.de>.
Ramez Ghazzaoui wrote:

> Today I realized that this very solution has broken the Java
> request.getParameter() method in JSP. Now, with the URIEncoding set to
> UTF-8, this Java method is misinterpreting non-English characters. When
> I invoke from the browser the following address:
> http://localhost/main.jsp?path=olé (or the equivalent
> http://localhost/main.jsp?path=ol%E9) a call to
> request.getParameter("path") from within main.jsp returns ol? where the
> question mark is character number 65533. That's way off from 233 (which
> is the correct U-dec for eacute, or é).

If you tell Tomcat that you'll provide URIs which are encoded in UTF-8 then do 
as you said and provide UTF-8-encoded URIs. Your example above should 
therefore look like
http://localhost/main.jsp?path=ol%C3%A9

If you're using HTML-forms with method="GET", set the accept-charset attribute 
of the form to UTF-8.

> Is there a way to make French characters work both in Directory Listings
> and in GET parameters?

Yes. See above.

Regards
  mks

---------------------------------------------------------------------
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