Logo 
Search:

Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

HOW TO : convert httpservletrequest into ISO-8859-1 ?

  Asked By: Caleb    Date: Jun 29    Category: Java    Views: 1324
  

I'm stuck for a while with this question :
I've got a servlet
I get the stream from httpservletrequest into a byte
(this stream is supposed to be UTF-8)
from this byte I go to ISO-8859-1 with this code :

< --- partial code --- >
String inputEnc = "UTF-8"; //actually, I read the header's content-
type to get this information
String outputEnc = "ISO-8859-1"; //ouput encoding needed for I can
receive german / franch / ... characters
InputStream in = req.getInputStream();
byte[] tabByte = new byte[req.getContentLength()];
int offset = 0;
do {
int inputLen = in.read(tabByte, offset, req.getContentLength() -
offset);
if (inputLen <= 0) {
String msg = "err.io.short_read (input length <=0)";
throw new IllegalArgumentException(msg);
}
offset += inputLen;
}
while (req.getContentLength() - offset > 0);
in.close();
strInput = new String( (new String(tabByte)).getBytes
(inputEnc) ,outputEnc );
</ --- partial code --- >

My problem is that when I do this, it seems the servlet double
encodes the input stream
In otherwords, when I receive this stream (UTF-8 encoded) :
Größe (read G R umlaut-A reversed-P umlaut-A umlaut-Y E)
I want to get (ISO-8859-1 encoded) wich fit what a book would print :
Größe (read G R umlaut-O german-Beta E)

Share: 

 

No Answers Found. Be the First, To Post Answer.

 
Didn't find what you were looking for? Find more on HOW TO : convert httpservletrequest into ISO-8859-1 ? Or get search suggestion and latest updates.




Tagged: