Java Mailing List Archive

http://www.junlu.com/

Home » Home (12/2007) » Tomcat Users »

Re: Servlet on Tomcat + Oracle +ISU 8859-8 (Hebrew CharSet) - encodin
g problem

Veniamin Fichin

2004-03-31

Replies:

This is my problem also, and sadly it's so since long time I use Tomcat.

  I've attach a simple little test case .war file to reproduce the
problem. There are four HTML forms there, two of them submits to JSP
page (GET and POST methods), others go to servlet (same methods).
  On top of it is a select field allowing to define an encoding for
future submits. It acts as following: after choosing it and submitting
that select the JSP page is reloaded with that encoding, setting its
response.setContentType() and setting session attribute named
"tHAVW07QUf" (for uniqueness, see below). Now, one can submit any form
presented below.
  I've deployed a filter.SetCharacterEncodingFilter (taken from
standard Tomcat distribution), with one modification: during every
request it reads session attribute "tHAVW07QUf" and sets requests'
encoding accordingly. If that attribute is absent, it reads its init
parameter given in web.xml as usually. So, instead of hard-coding
character incoding in web.xml, I can set it online. According to
filters.RequestDumperFilter (also Tomcat's standard filter) it works.
  So, let's see what we have here. The result on my machine is that
any GET methods produces broken output of the parameter passed as
URL-encoded %XX%XX%XX string, actual encoding of which is set by select
box on the first page. Any combinations of encoding, submit methods and
target actions (JSP or Servlet) give me broken output, except two of
them -- utf-8 POST to JSP and utf-8 POST to Servlet.
  I looked at Tomcat's some source files, namely
org.apache.catalina.util.RequestUtil.URLDecode(byte[], String) and
org.apache.catalina.util.RequestUtil.parseParameters(java.util.Map,
byte[], String), and see how url-encoded request parameters are parsed,
but I don't know if it's the right place to see.
  Ah, and one note. I tried to run Tomcat with
"-Dfile.encoding=koi8-r" option to set default byte[]->String conversion
mapping to koi8-r (for example), and even this does not help me much,
though it sets the new default.
  This behaviour was there on 4.x and 5.x versions, seems like nothing
is changing.

  I don't state that I've done all tests correctly, so in any error
please fix my mind. The only question is: how one can universally and
correctly handle non-ASCII request parameters and get rightly decoded
output?

yair.fine@(protected):

> Hi all ,
> i have a problem with encoding and decoding, from a servlet , running on
> Tomcat , to Oracle DB.
> I hope it is the right forum for that , and i appologize if ti is not ..
>
> The problem:
> I am using Oracle 8.1.7 DB , in a Charest ISU 8859-9-8 ( Hebrew ), I use a
> thin client as the JDBC driver .
> I have a servlet that all it does is getting and updating one of the table
>
> The character set in the servlet is too , ISO 8859-8 . This is done this
> way:
>
> public void doGet(HttpServletRequest request, HttpServletResponse response)
>  throws ServletException, IOException {
>  
>  request.setCharacterEncoding("ISO-8859-8");
>  response.setContentType("Text/html; ISO-8859-8");
>  .....
> }
>
> I use the doGet method of a servlet to get parameters to retrieve from
> Oracle. this is done through the URL, for example :
> I send the parameters like this :
> http://localhost:8080/myapp/myapp?name=yair
> <http://localhost:8080/myapp/myapp?name=yair&family=fine> &family=fine
> for name= yair, family = fine
>
> There is no problem in getting and inserting English characters.
> There is a problem when i try to get or to insert Hebrew characters.
> i get ???? in DB , for both if i write yair in the url in Hebrew , or i
> write yair in %E9%E9%E9%F8 which is the decimal representation
>
> For example , if i insert a string in Hebrew , it looks like this "?????" (
> in SQL +)
>
>
> this is how i get the requests from the url
> Enumeration paramEnum = request.getParameterNames(); // get request
> parameters from the url , in param/value pairs
> String myParam = (String) paramEnum.nextElement(); //get parameter
> String myValue = request.getParameter(myParam); //get value
>
> String myStatment = "insert into mytable values('19', '"+myValue+"')" insert
> to table 19 , myvalue
> ResultSet rs = stmt.executeQuery(myStatment);
>
> does any one have a solution for that ?


Attachment: charset.renametowar.gz
---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@(protected)
For additional commands, e-mail: tomcat-user-help@(protected)
©2008 junlu.com - Jax Systems, LLC, U.S.A.