java - thai character showing ????? mark on file upload in jsp

I have a JSP/Servlet application works as follow:

1- upload an excel sheet from a jsp page

2- read the content and add them to mySQL in Servlet/Java code

the problem that when i have arabic characters in the excel it will be added to the DB as

???? in the JSP file i changed the page encoding as follow:

               <%@ page language="java" 
              contentType="text/html; charset=utf-8"
              pageEncoding="utf-8"%>
               <meta http-equiv="Content-Type"
             content="text/html; charset=utf-8">

in the html form where the file upload input i added enctype=

             "multipart/form-data;charset=utf-8"

I tested the mySql and it supports arabic letters (I can insert and select via the console) and when i try to read something from the DB in arabic and view it in the JSP it works fine!it is working correctlly on my local syatem but when i deploying the war file on server.then upload the excel file it show ????? mark in database

I think the problem is in the part of the upload! Any one can help please?

Thanks

2 Answers

  1. Oliver- Reply

    2019-11-14

    When you read the excel file in your servlet, you should read that file a UTF8 stream. Then, when you insert the data into database, the connection you used for inserting must declare as a UTF8 connection, for an example

    DriverManager.getConnection( "jdbc:mysql://"+host+"/"+dbName+"?useUnicode=true&characterEncoding=UTF-8",user,pass);
    
  2. Oscar- Reply

    2019-11-14

    I think the problem is the encoding of the Excel file. The encoding of the HTML does not matter if you are reading the data from another source (the sheet). If the excel is uploaded from a Windows system, the encoding is probably not UTF-8, but CP-1252CP-1256

    UPDATE: Windows-1252 is the Latin one, for arabic characteres windows uses windows-1256, based on ISO 8859-6. UTF-8 uses 1 to 4 bytes for each character, while ISO 8859 uses only one for each one, so problems will rise if you mix both.

Leave a Reply

Your email address will not be published. Required fields are marked *

You can use these HTML tags and attributes <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>