You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Joe Tomcat <to...@mobile.mp> on 2003/02/09 12:46:55 UTC
Handling non-Latin chars in servlet, jdbc
Hello fellow Tomcatists,
It is time for my web app to move beyond the confines of the A-B-Cs.
This app takes user input from web forms, stores it in various fields in
a database, and then displays it back in various ways. The goal is to
have it so that a user can enter Japanese or other Asian language chars
into the form in his browser, the web app stores the form input in the
db, and later on, displays it back to the browser and the chars show up
the right way.
It seems like this should be easy. Java is designed for multibyte, and
I think Postgres can also store multibyte chars, but I'm running into a
block. My friend in Japan entered some chars into a form, and hit
submit, and what was stored in the db were html entities. Then, when he
displayed it back to his browser, it was a problem because my output
code automatically escapes html entities, so what he saw was "&48832;"
or something, instead of the ji he was expecting.
Does anyone have some tips on this, or pointers to articles or books I
should be reading about how to do this?
Thanks!
---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
Re: How can I get the web application name?
Posted by Sean Dockery <se...@sbdconsultants.com>.
HttpServletRequest.getRealPath("/") should get the document root of your web
application.
HttpServletRequest.getContextPath() should get the path (name) on which the
context is mounted.
ServletContext.getServletContextName() should get the description (name) of
the application.
Sean Dockery
sean@sbdconsultants.com
Certified Java Web Component Developer
Certified Delphi Programmer
SBD Consultants
http://www.sbdconsultants.com
----- Original Message -----
From: "Etienne" <et...@sympatico.ca>
To: "'Tomcat Users List'" <to...@jakarta.apache.org>
Sent: Tuesday, February 11, 2003 05:30
Subject: How can I get the web application name?
> Hi, I found a way to retrieve the web application name for WebSphere I
> guess. Can I do the same for Tomcat?
>
> Thanks.
>
> Etienne.
>
>
>
> > George,
> > I've got a small servlet that'll show the docroot. Check out
> > http://home.nc.rr.com/hygh/was/WebAppName.java
> >
> > Ken
> >
> > George wrote:
> >
> > > Hi,
> > > In a servlet, I want to get the Web Application Name in which the
> servlet
> > > belongs.
> > > Actually, I want to retrieve the webapp docRoot using
> > >
> > > I found in ServletEngineConfigDumper example the following code, but
> I need
> > > the webappname
> > >
> > > ServletEngineInfo engineInfo =
> ServletEngine.getEngine().getInfo();
> > > ServletHostInfo vhinfo =
> > > engineInfo.getServletHostInfo("default_host");
> > > WebGroupInfo wgInfo =
> vhinfo.getWebGroupInfo("webappname");
> > > String docroot=wgInfo.getDocumentRoot();
> > >
> > > Any other way to get the WebApplication Doc Root?
> > >
> > > Thank you
> > > George
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
RE: How can I get the web application name?
Posted by Etienne <et...@sympatico.ca>.
Yes, I guess.
(....)
Thanks.
E.L.
-----Original Message-----
From: Tim Funk [mailto:funkman@joedog.org]
Sent: February 11, 2003 7:44 AM
To: Tomcat Users List
Subject: Re: How can I get the web application name?
Do you mean HttpServletRequest.getContextPath()?
-Tim
Etienne wrote:
> Hi, I found a way to retrieve the web application name for WebSphere I
> guess. Can I do the same for Tomcat?
>
> Thanks.
>
> Etienne.
>
>
>
>
>>George,
>>I've got a small servlet that'll show the docroot. Check out
>>http://home.nc.rr.com/hygh/was/WebAppName.java
>>
>>Ken
>>
>>George wrote:
>>
>>
>>>Hi,
>>>In a servlet, I want to get the Web Application Name in which the
>
> servlet
>
>>>belongs.
>>>Actually, I want to retrieve the webapp docRoot using
>>>
>>>I found in ServletEngineConfigDumper example the following code, but
>
> I need
>
>>>the webappname
>>>
>>> ServletEngineInfo engineInfo =
>
> ServletEngine.getEngine().getInfo();
>
>>> ServletHostInfo vhinfo =
>>>engineInfo.getServletHostInfo("default_host");
>>> WebGroupInfo wgInfo =
>
> vhinfo.getWebGroupInfo("webappname");
>
>>> String docroot=wgInfo.getDocumentRoot();
>>>
>>>Any other way to get the WebApplication Doc Root?
>>>
>>>Thank you
>>>George
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
Re: How can I get the web application name?
Posted by Tim Funk <fu...@joedog.org>.
Do you mean HttpServletRequest.getContextPath()?
-Tim
Etienne wrote:
> Hi, I found a way to retrieve the web application name for WebSphere I
> guess. Can I do the same for Tomcat?
>
> Thanks.
>
> Etienne.
>
>
>
>
>>George,
>>I've got a small servlet that'll show the docroot. Check out
>>http://home.nc.rr.com/hygh/was/WebAppName.java
>>
>>Ken
>>
>>George wrote:
>>
>>
>>>Hi,
>>>In a servlet, I want to get the Web Application Name in which the
>
> servlet
>
>>>belongs.
>>>Actually, I want to retrieve the webapp docRoot using
>>>
>>>I found in ServletEngineConfigDumper example the following code, but
>
> I need
>
>>>the webappname
>>>
>>> ServletEngineInfo engineInfo =
>
> ServletEngine.getEngine().getInfo();
>
>>> ServletHostInfo vhinfo =
>>>engineInfo.getServletHostInfo("default_host");
>>> WebGroupInfo wgInfo =
>
> vhinfo.getWebGroupInfo("webappname");
>
>>> String docroot=wgInfo.getDocumentRoot();
>>>
>>>Any other way to get the WebApplication Doc Root?
>>>
>>>Thank you
>>>George
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
RE: How can I get the web application name?
Posted by Daniel Brown <gm...@blueyonder.co.uk>.
For Tomcat 4.x (Servlet 2.3), you can use
ServletContext.getServletContextName()
You could also use HttpServletRequest.getContextPath(), if that's suited to
what you want to do.
Dan.
> -----Original Message-----
> From: Etienne [mailto:etienno@sympatico.ca]
> Sent: 11 February 2003 12:31
> To: 'Tomcat Users List'
> Subject: How can I get the web application name?
>
>
> Hi, I found a way to retrieve the web application name for WebSphere I
> guess. Can I do the same for Tomcat?
>
> Thanks.
>
> Etienne.
>
>
>
> > George,
> > I've got a small servlet that'll show the docroot. Check out
> > http://home.nc.rr.com/hygh/was/WebAppName.java
> >
> > Ken
> >
> > George wrote:
> >
> > > Hi,
> > > In a servlet, I want to get the Web Application Name in which the
> servlet
> > > belongs.
> > > Actually, I want to retrieve the webapp docRoot using
> > >
> > > I found in ServletEngineConfigDumper example the following code, but
> I need
> > > the webappname
> > >
> > > ServletEngineInfo engineInfo =
> ServletEngine.getEngine().getInfo();
> > > ServletHostInfo vhinfo =
> > > engineInfo.getServletHostInfo("default_host");
> > > WebGroupInfo wgInfo =
> vhinfo.getWebGroupInfo("webappname");
> > > String docroot=wgInfo.getDocumentRoot();
> > >
> > > Any other way to get the WebApplication Doc Root?
> > >
> > > Thank you
> > > George
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
>
---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
How can I get the web application name?
Posted by Etienne <et...@sympatico.ca>.
Hi, I found a way to retrieve the web application name for WebSphere I
guess. Can I do the same for Tomcat?
Thanks.
Etienne.
> George,
> I've got a small servlet that'll show the docroot. Check out
> http://home.nc.rr.com/hygh/was/WebAppName.java
>
> Ken
>
> George wrote:
>
> > Hi,
> > In a servlet, I want to get the Web Application Name in which the
servlet
> > belongs.
> > Actually, I want to retrieve the webapp docRoot using
> >
> > I found in ServletEngineConfigDumper example the following code, but
I need
> > the webappname
> >
> > ServletEngineInfo engineInfo =
ServletEngine.getEngine().getInfo();
> > ServletHostInfo vhinfo =
> > engineInfo.getServletHostInfo("default_host");
> > WebGroupInfo wgInfo =
vhinfo.getWebGroupInfo("webappname");
> > String docroot=wgInfo.getDocumentRoot();
> >
> > Any other way to get the WebApplication Doc Root?
> >
> > Thank you
> > George
---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
Re: Handling non-Latin chars in servlet, jdbc
Posted by Sean Dockery <se...@sbdconsultants.com>.
I believe that MySQL assigns a character set to a database when it is
created--taking the system default if you do not specify a different
character set. I do not believe that putting the encoding setting into the
connection URL is necessary when you have created the database with your
desired character set. That is from memory... Can anyone confirm this?
Sean Dockery
sean@sbdconsultants.com
Certified Java Web Component Developer
Certified Delphi Programmer
SBD Consultants
http://www.sbdconsultants.com
----- Original Message -----
From: "mech" <me...@rz.fh-augsburg.de>
To: "'Tomcat Users List'" <to...@jakarta.apache.org>
Sent: Tuesday, February 11, 2003 05:20
Subject: RE: Handling non-Latin chars in servlet, jdbc
>
>
> > -----Original Message-----
> > From: Joe Tomcat [mailto:tomcat@mobile.mp]
> > Sent: Sonntag, 9. Februar 2003 12:47
> > To: Tomcat Users List
> > Subject: Handling non-Latin chars in servlet, jdbc
> >
> >
> > Hello fellow Tomcatists,
> >
> > It is time for my web app to move beyond the confines of the A-B-Cs.
> > This app takes user input from web forms, stores it in
> > various fields in a database, and then displays it back in
> > various ways. The goal is to have it so that a user can
> > enter Japanese or other Asian language chars into the form in
> > his browser, the web app stores the form input in the db, and
> > later on, displays it back to the browser and the chars show
> > up the right way.
> >
> > It seems like this should be easy. Java is designed for
> > multibyte, and I think Postgres can also store multibyte
> > chars, but I'm running into a block. My friend in Japan
> > entered some chars into a form, and hit submit, and what was
> > stored in the db were html entities. Then, when he displayed
> > it back to his browser, it was a problem because my output
> > code automatically escapes html entities, so what he saw was
> > "&48832;" or something, instead of the ji he was expecting.
> >
> > Does anyone have some tips on this, or pointers to articles
> > or books I should be reading about how to do this?
> >
> First:
> Make sure that your generated html page has a content header that tells
> the browser what content encoding you want. Otherwise your browser might
> imply Latin for parsing even if you want Unicode.
> Things like: <%@ page contentType="text/html; charset=xyz" %> or <meta
> http-equiv="content-type" content="text/html; charset=xyz"> might help.
>
> Second (from own bad experience ;-)):
> I use MySQL which also support Unicode. But you have to set the encoding
> you want MySQL to use. Otherwise it tries to find the encoding by
> checking the systems default. Ran into trouble because my development
> server had a German installation whereas my productive machine has an
> English setup. So I had "Latin" vs. "Latin-1". I wondered what happend
> to my German special characters, but actually the problem was that my
> JDBC driver talked the wrong encoding to the database and the problem
> was already located in my data access classes, not the jsp or html
> processing.
> After telling MySQL in the connection url to use Latin-1 encoding my
> problem was gone.
>
> So you should also check that your problem is not located on the
> database/driver side and your characters get garbled already there.
>
>
> Michael
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
>
---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
RE: Handling non-Latin chars in servlet, jdbc
Posted by mech <me...@rz.fh-augsburg.de>.
> -----Original Message-----
> From: Joe Tomcat [mailto:tomcat@mobile.mp]
> Sent: Sonntag, 9. Februar 2003 12:47
> To: Tomcat Users List
> Subject: Handling non-Latin chars in servlet, jdbc
>
>
> Hello fellow Tomcatists,
>
> It is time for my web app to move beyond the confines of the A-B-Cs.
> This app takes user input from web forms, stores it in
> various fields in a database, and then displays it back in
> various ways. The goal is to have it so that a user can
> enter Japanese or other Asian language chars into the form in
> his browser, the web app stores the form input in the db, and
> later on, displays it back to the browser and the chars show
> up the right way.
>
> It seems like this should be easy. Java is designed for
> multibyte, and I think Postgres can also store multibyte
> chars, but I'm running into a block. My friend in Japan
> entered some chars into a form, and hit submit, and what was
> stored in the db were html entities. Then, when he displayed
> it back to his browser, it was a problem because my output
> code automatically escapes html entities, so what he saw was
> "&48832;" or something, instead of the ji he was expecting.
>
> Does anyone have some tips on this, or pointers to articles
> or books I should be reading about how to do this?
>
First:
Make sure that your generated html page has a content header that tells
the browser what content encoding you want. Otherwise your browser might
imply Latin for parsing even if you want Unicode.
Things like: <%@ page contentType="text/html; charset=xyz" %> or <meta
http-equiv="content-type" content="text/html; charset=xyz"> might help.
Second (from own bad experience ;-)):
I use MySQL which also support Unicode. But you have to set the encoding
you want MySQL to use. Otherwise it tries to find the encoding by
checking the systems default. Ran into trouble because my development
server had a German installation whereas my productive machine has an
English setup. So I had "Latin" vs. "Latin-1". I wondered what happend
to my German special characters, but actually the problem was that my
JDBC driver talked the wrong encoding to the database and the problem
was already located in my data access classes, not the jsp or html
processing.
After telling MySQL in the connection url to use Latin-1 encoding my
problem was gone.
So you should also check that your problem is not located on the
database/driver side and your characters get garbled already there.
Michael
---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org