Data with special characters is not displaying properly in jsp - java

Below are my application's oracle database characters settings.
There are some jobs running in the background to sync data from another application to my application.
Once I open the application, the data which is coming from another application is not displaying properly.
There are some special characters are coming with the data. So to avoid these special characters, I placed the encoding at JSP page level to UTF-8.
Now the data is displaying properly.
Everything is working fine. Now when I try to add the data from my application, which is having some Swedish characters, then those characters are not displaying properly.
So now I changed the encoding from UTF-8 to ISO-8859-1. Now the data which was entered from my application was displaying properly, but the data which was coming from another application is not displaying properly. I have checked my URIencoding at Apache Tomcat's server.xml and it is pointing to UTF-8 only.
Also I added the below code in Controller servlet from which every jsp page is displayed.
request.setCharcterEncoding("UTF-8");
response.setCharcterEncoding("UTF-8");
But still now UTF-8 encoding is working only for the data which is synch/coming from another application. This is not working for the data which is entering from my application.

Related

Supplementary character support in Java web application with Mysql

I am able to enter supplementary chars in textbox but it doesn't get save in database. I am using MySql database. I have used spring and hibernate in my application. What change should I make to enable supplementary chars support in my application?
Following is my database connection string:
url="jdbc:mysql://localhost:3306/users?useUnicode=true&characterEncoding=utf8"
You need to do following changes to make your application supplementary character compatible:
Remove characterEncoding i.e. utf8 from your url and make it as below:
url="jdbc:mysql://localhost:3306/users?useUnicode=true"
You need to edit my.ini file from MySQL Server directory. If you have Windows 64bit OS, then you may find it at following location:
C:\ProgramData\MySQL\MySQL Server 5.6\my.ini
Open this file using any text editor such as Notepad++ and change the following parameter value:
From
character-set-server=utf8
To
character-set-server=utf8mb4
After making the above changes your application should support Supplementary characters.

RestAPI in Java with MySQL DB: issue on storing data with diacritics

I am building an app and I can't seem to handle the data that contain diacritics or other type of UTF-8 characters. In my case I'm in need of this chars: ă-Ă-â-Â-î-Î-ş-Ş-ţ-Ţ.
Now, first, there is a input on the front-end that gathers some info from the users, sends it via AngularJS http module to the API. The headers are all good, the data goes to the API all good. Then, on the server side, if I log the info, it outputs: ?-?-â-Â-î-Î-?-?-?-?, and of course, the same info is put in the db (checked with phpmyadmin).
The weird thing is, as my app pulls the data from the db to print it to my app, all goes well, it prints as it should be ă-Ă-â-Â-î-Î-ş-Ş-ţ-Ţ, until I restart the server, after which it prints as it is shown in the db.
I want to point out that it isn't the cache, I'm testing the app in cache-free environment. I even tried to access from different end-points just to be sure it is not from some local issue.
Anyone has any ideas ?
I solved it myself: the problem was from JPA persistence level from Java. It didn't interpret the UTF-8 right because I was giving it inside the url. Actually what I needed to do was to create a parameter in glassfish jdbc.

Glassfish local and external server encodes characters differently

I am importing some .csv files, which gets inserted into my database. When I run the Glassfish server on my local server through NetBeans, the data is being inserted without errors and it shows the correct characters (æøå being the main characters).
However, when I upload the files to my Glassfish server and redeploy it (using my .war file), the characters look all weird when I upload the .csv file and it inserts the data into the database.
When I upload my file locally and execute it locally (but gets insert into the server), it will look like this:
Idrætsforening
But when I upload and redeploy my project, it looks like this:
Idr��tsforening
When I do System.out.println() with the data locally, the data is shown correctly. When I do it on my server, the æøå characters are shown as ?. So it will say Idr?tsforening
I am not sure what code I can show you, but I did add ?characterEncoding=utf8 to my JDBC connection and I did add a property to my Connection Pool on my Glassfish server: characterEncoding = UTF-8.
What could be wrong?

Jasper report printing on client side

On WebSphere portal I am trying to use JasperReport print functionality.
JasperPrintManager.printReport(jasperPrint, true);
This way works fine for WAS and localhost.
But when I deploy the application on Remote server, the dialog of print is not appearing and no printing work is done.
Although I have used JavaPrint service to lookup all the printers and then select one for printing the task but it is not even working that way.
Your solution works on localhost because your client and server are the same machine. Thus calling a print command on the server side will make it look like it's printing from the client.
But you don't want it to print on server. You want the client's browser to have access to the report in a printable format. A common format is PDF.
As #AlexK mentions in the comments, there are already multiple other questions (with answers) on how to do this.
My suggestion for getting this done in a portlet is to have a button in your portlet view that will make a call to a serveResourceURL and download a PDF version of the report. The serveResource method was designed for situations like this where developers need to serve content other than HTML.

Content coming from a web application sometimes randomly shuffled

We develop a Java web application which is run on Tomcat. It's been installed on many computers and it's working without problems. Recently, on a single remote installation, it exhibits very strange behavior: Sometimes content coming through HTTP to the browser is randomly shuffled - wrong data being served for a given URL. Most often it manifests as images being randomly exchanged on a web page. But it's not limited to images, it happened to me that instead of a HTML page the browser got one of the images instead.
I tried to debug the problem using FireBug + NetExport, and so far I gathered:
It appears randomly. Most of the time content is error-free, the problem occurs only from time to time.
The same application runs on many installations, but only this single installation produces the error.
It's not connected to a particular browser - we tried different browsers from different computers and the problem persists.
It occurs when viewed from the server itself (localhost) too, which rules out some broken transparent proxy on the way.
Both images and HTML pages are affected.
If wrong content is received, the data itself is consistent: Content-Length, Content-Type, ETags, etc. - everything matches the content. Just that it's wrong data for a given URL.
I'm truly puzzled, I've never seen such an error. I'd be grateful for any ideas how to investigate the problem further.

Categories