私は新米プログラマーのようなもので、扱っているコードにいくつか問題があります。
基本的に、コードは別の JSP からフォームを受け取り、バイトを読み取り、データを解析し、DataInputStream を使用して結果を SalesForce に送信します。
//Getting the parameters from request
String contentType = request.getContentType();
DataInputStream in = new DataInputStream(request.getInputStream());
int formDataLength = request.getContentLength();
//System.out.println(formDataLength);
byte dataBytes[] = new byte[formDataLength];
int byteRead = 0;
int totalBytesRead = 0;
while (totalBytesRead < formDataLength)
{
byteRead = in.read(dataBytes, totalBytesRead, formDataLength);
totalBytesRead += byteRead;
}
正常に動作しますが、コードが通常の文字を処理する場合のみです。特殊文字 (フランス語の文字: àâäæçéèêëîïôùûü など) を処理しようとするたびに、結果として次の意味不明な結果が得られます。
ã¢ãã¦ã§ã©ã¨ãªãããããããã¹ãã¼
DataInputStream の問題である可能性があり、UTF-8 でエンコードされたテキストが返されないことを理解しています。この問題に取り組む方法について何か提案はありますか?
すべての .jsp ファイルには <%@page pageEncoding="UTF-8" contentType="text/html; charset=UTF-8"%> が含まれており、Tomcat の設定は問題ありません (URI = UTF-8 など)。追加してみました:
request.setCharacterEncoding("UTF-8");
と
response.setCharacterEncoding("UTF-8");
無駄に。
データを解析する方法の例を次に示します。
//Getting the notes for the Case
String notes = new String(dataBytes);
System.out.println(notes);
String savenotes = casetype.substring(notes.indexOf("notes"));
//savenotes = savenotes.substring(savenotes.indexOf("\n"), savenotes.indexOf("---"));
savenotes = savenotes.substring(savenotes.indexOf("\n")+1);
savenotes = savenotes.substring(savenotes.indexOf("\n")+1);
savenotes = savenotes.substring(0,savenotes.indexOf("name=\"datafile"));
savenotes = savenotes.substring(0,savenotes.lastIndexOf("\n------"));
savenotes = savenotes.trim();
前もって感謝します。