I'm developing a web application in Spring Framework under Wildfly 10 application server. I use Eclipse IDE.
I experienced problems with the character encoding which I wasn't able to solve: some of the characters doesn't appear properly when I send them from server side to client side.
My test String object I use is "árvíztűrő tükörfúrógép"
When I read the value from database and send it to the client side, everything appears fine.
When I set the String value in the Controller as a ModelAndView object, it appears as '??rv?zt?±r?? t??k?¶rf??r??g?©p'
When I send the value from client side by ajax as a POST variable and send it back to client side, it appears as 'árvízt?r? tükörfúrógép'.
I set all the .jsp files encoding UTF8: <%#page contentType="text/html" pageEncoding="UTF-8"%>
In Eclipse I set all the Maven modules text file encoding to UTF8. All the files are in UTF8.
What did I miss? What else should I set to get the String value right on client side? Should I set the character encoding in Wildfly 10 somehow?
Could somebody help me? If you need further information, please don't hesitate to ask. Thank you.
EDIT: Setting the character encoding as Maven property solved the second case. Now I only have problems with the third case:
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
After nearly 2 months of searching I was able to find solution to my problem. In addition to configure the server and Spring, I needed to add two more things:
On the web module of my Maven project I had to set the character encoding of the source:
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
Also when I sent JSONObject to client side, I had to set the character encoding:
#RequestMapping(value = "/historyContent.do", produces = { "application/json; charset=UTF-8" })
And finally I can see what I wanted.
Related
I have an application which is a set of Java Web Services and some static content (HTML, XML, JavaScript, etc.). I know that JavaScript has a limited character encoding that is possible, but HTML and XML can use various character encodings. I happen to know that all of these files are UTF-8 encoded. The WebSphere application server that I am using properly sets the Content-Type to 'text/html; charset=utf-8' for the HTML, but not for JavaScript or XML. They get the Content-Type header set to 'application/javascript' and 'text/xml' respectively. My security folks are telling me that ot specifying the charset for the XML files is a vulnerability. Remember these are static files.
On an IBM HTTPD web server (in front of the WebSphere application server) is there a directive that I can use to add the character encoding to the content type of 'text' types? On WebSphere is there a directive I can use to set the default character encoding for text types? I assume that after I "fix" this for the XML files that I will then be asked to fix it for CSS files, JavaScript files, etc. I would rather fix it once and be done.
If this question has been asked before, please provide the URL. I did find this question, but it is not the same. I am looking into the feasibility of this answer, but there are many folders and I would rather not have to remember to add a .htaccess file with this directive to each one.
You can just append AddDefaultCharset utf-8 to httpd.conf and everything will go out with that charset appended to it, even content generated by the application server. htaccess is not necessary and not useful for appserver content.
If you find you need to blacklist context roots, extensions,
or anything else, sue <LocationMatch> with AddDefaultCharset off.
Unfortunately Header edit Content-Type... will not work in IBM HTTP Server prior to V9. In V9 this allows you to easily cherry pick the current Content-Type:
Header always edit Content-Type ^(text/html)$ "$1 ; charset=utf8"
Header always edit Content-Type ^(application/javascript)$ "$1 ; charset=utf8"
Just as same as covener described:
Add the following lines into the conf/httpd.conf file:
AddDefaultCharset utf-8
AddCharset utf-8 .html .js .css
<Location />
Header always edit Content-Type ^(text/html)$ "$1; charset=utf8"
Header always edit Content-Type ^(application/javascript)$ "$1; charset=utf8"
RewriteRule ^(.*)$ $1 [R=200,L]
</Location>
and it should work.
URL:http://localhost:8080/admin/users/8VHlQMoMAeGAfwADT%2FtM2Q%3D%3D
When i try to hit the above URL using advanced rest client, i am getting 400:Bad Request.
I need special characters to be passed in URl path via URL encoding only. But %2F is not being accepted.How to enable jboss to accept encoded slash in url? kindly help.
First of all you have to know that JBoss by default is not allowing the escaped slashes in paths for security reasons.
However you can set the following system property to true
org.apache.tomcat.util.buf.UDecoder.ALLOW_ENCODED_SLASH
I have created and am running some birt reports in a java application using birt 3.7.2,
which are called from a jsp page like the followingL
birt:viewer id="birtViewer" reportDesign="reportName" pattern="frameset" showTitle="false" height="450" width="1058" format="html" scrolling="no" showParameterPage="false">
</birt:viewer>
These reports are working fine in all browsers except in IE 9. (working in IE 8 well).
I have to use BIRT in IE9 without adding meta compatible tag, as we're using metro UI, so the following :
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" >.
We can not use the meta tag because we are using metro UI there which is not compatible with IE 8.
Check HTTP requests to confirm that you have percent encoded characters in you HTTP requests.
IE9 has a problem with percent encoded characters in URL.
KB article explaining it is by design.
Blog post explaining how does URI mechanism work at older Windows platform.
I wasn't able to find a solution for it. I had option to not to use encoding of URL requests to BIRT. I bypassed problem converting characters which needed encoding in something I understand and then replacing those converted character in BIRT script to its original value.
I host a 10 year old java (jar) based web service on Tomcat.
The original source for this service no longer exists (actually the firm that created the service no longer exists and there doesn't seem to be any way to find the former principals).
I packet captured the "Data" field in the url and include a snip of it below.
I'm hoping someone will recognize the encoding used on this field - it does not appear to be standard where the rest of the URL encoding it no problem. So I'm thinking the application posting the data field first encodes the field (which is then again encoded for the URL post command.
http:// ... &CompletedBillableTransactionFlag=&Data=%F0j%B2g%1F-%95%F7%E3E%C0q%A6%12%11%B2%7C%D8%C7%F6%C8%24 ... I could have included the rest of the fields value but thought to keep it short.
I have a multipart / form-data form to upload a csv file to a rest easy (JAX RS) webservice. This file can contain
iso-8859-1 characters like for example é. When I upload the file through Firefox these characters are garbled and they end up like a ?. When I upload the file through Internet Explorer everything works fine.
I've done a lot of reading and found out that there's a problem in firefox combining multipart / form-data and the charset attribute (enctype='multipart/form-data; charset=ISO-8859-1') doesn't work.
So I've tried setting <meta http-equiv="Content-Type" content="text/csv; charset=iso-8859-1" /> in my HTML page (I also tried setting text/html or multipart/form-data in stead of text/csv but none of that seems to make a difference.
I went through the rest easy api and found something about 'overwriting the default fallback content type for multipart messages'. The default fallback when no content type is found is us-ascii. The characters I try to process (é,..) don't exist in us-ascii so it makes sense they end up garbled. Overriding this default fallback content type doesn't seem to help either (see: http://docs.jboss.org/resteasy/docs/1.2.GA/userguide/html/Multipart.html)
So am I right when I say that Internet Explorer sends the content-type+charset correctly in the http header, so everything goes well. And that firefox messes things up while trying to send the content-type/charset while combined with multipart/form-data? I have done my searching through stackoverflow but none of the approved solutions seem to work in my case.
Has anybody had this specific problem before? (multipart / form-data file upload using Jboss rest easy framework)? Something else I can try?
Thanks in advance!
Yannick