the scenario is like this :
datepicker jquery ui in french needs the page to be encoded iso (because with utf , there are some french character that are not well displayed)
<%# page language="java" import="java.util.*" pageEncoding="ISO-8859-1"%>
and i have some arabic data that i need to store in the database, for this the page must be encoded in utf_8
<%# page language="java" import="java.util.*" pageEncoding="UTF-8"%>
data is sent via ajax
what to do ?
In this situation I believe you should always publish with UTF-8. But you need to make sure that all declared encodings agree. For example, for HTML, any encoding declared in a <meta> tag should agree with the actual Content-type HTTP header.
The only reason I can think of to publish in ISO-8859-1 instead of UTF-8 is if you have a client that you cannot change that requires this encoding. But even in that case, hopefully you would be able to use a User-Agent request header to identify this client and serve ISO-8859-1 only to that client.
Related
I'm using Visual Studio 2015 enterprise version, and editing cshtml page.
I would like to display Chinese characters like 中国China. After I save it. It will display ??China in html code. I have checked the page is in utf-8 character set.
All help are appreciated.
The code is as follows:
<h2>中国China</h2>
Is there any view-page code setting in somewhere?
First of all, depending on your browser, set its encoding format to "auto detect/Unicode" to ensure Unicode format used.
Firefox: View => Text Encoding => Auto Detect/Unicode
Chrome: Pop-out side menu => More tools => Encoding => Auto detect/Unicode
If the browser can't display those characters properly after encoding settings changed, set the meta tag on your Layout/view page as this to declare Chinese encoding GB-2312:
<meta charset="GB2312" />
and/or use language attribute on html tag:
<html lang="zh-Hans">...</html>
Other way to change page language encoding on view page is using File => Save As, click the drop down arrow besides Save button to see Advanced Save Options, then choose proper codepage for your page (by default it sets as Unicode (UTF-8 with signature) - Codepage 65001.
Additional note: Ensure you have at least a Unicode font with CJK characters available on your system Fonts directory.
Similar problem: how to display chinese character in HTML
I am developing a site in mvc4 where the content of the site includes both latin and cyrillic characters. Both are included in markup and both display correctly on screen.
However, within the markup, I have seen issues with cyrillic where url's for example are like following:
/%d1%81%d0%bf%d0%b8%d1%81%d0%be%d0%ba%20%d0%bf%d0%be%d0%b6%d0%b5%d0%bb%d0%b0%d0%bd%d0%b8%d0%b9
The url navigate correctly when clicked on, but incorrect in html markup. I have the meta charset set to utf-8 in a meta tag.
Any ideas whats causing this?
What you see is correct %-encoded (aka. URL-encoded) form of the URL “/список пожеланий” (as you can see using a decoder). Browser may display a URL in their address bar as %-encoded, or as decoded to characters. HTML authoring software or, in manual editing of HTML code, the author should take care of %-encoding anything that needs to be %-encoded at the HTTP protocol level, such as href attribute values.
I am using Rails 3.2.3 and Ruby 1.9.3.
I have a model called called Post that accepts a title and a description.
The front-end of the site receives information submitted through the back-end through an ajax request. When I fill out the form with, let's say
title: foo
content: foobar
and submit it, I am able to view data through the front-end without a problem.
However, whenever I submit non-utf8 data through the form, for example (mind the fancy quotes):
title: foo
content: “foobar”
When I try to render the form I get the following error:
ActionView::Template::Error (incompatible encoding regexp match (UTF-8 regexp with ASCII-8BIT string))
My .js.erb file looks like this:
$("#my_post").html('<%= escape_javascript(render :partial => 'post') %>');
I realize this is an issue with encoding, but I'm not sure how I should handle it the best way. I thought of several options:
Strip out non-utf8 by using the iconv library -- do this via a before_save filter for every single model in my application
Specifying at the top of the js that the document contains utf-8 (not sure this would work)
Using accept-charset="UTF-8" in my form to force the browser to avoid submission of non-utf-8 content.
I'm not even sure these solutions would help and the most efficient way to do this would be.
Thanks!
I suspect that you're not using the form helpers because you mention the question of adding accept-charset="UTF-8" to your form.
The form helpers will add the accept-charset attribute as well as the snowman parameter which together should ensure you get UTF-8 data from the browser.
See the Rails Form helpers guide.
You need to look carefully to see if
You're actually sending non-UTF-8 data to your app, or
You're sending UTF-8 data, but it is not being recognized by Ruby/Rails
To see which it is, you need to examine the data on the "wire." (What's being sent on the Internet.) Use a peeking tool such as Wireshark or a proxy spy such as Fiddler
Curly quotes can be sent using 8859 or UTF-8.
Recommendation You should set the HTML page to be UTF-8. Any Ajax sent from scripts on the page should then also use UTF-8. See http://www.utf8.com/
Added (Re: comment about how Rails sets form's character encoding)
The issue for Ajax character encoding is how was the page's encoding set. A blog post. So be sure to set the page's UTF-8 encoding in your page template.
When I submit a jsp page and the request goes to a portlet controller, I want the french characters on the jsp page to be encoded always using UTF-8 in the portlet controller.
What is the code syntax that I need to use in jsp or portlet controller to ensure this?
For me works
<%# page language="java" import="java.util.*" pageEncoding="UTF-8"%>
in the top of the JSP
We have translated one of our pages to french and all the html within the page displays flawlessly. That said, there is a javascript table (ext js) and the accented characters are not displaying correctly. The page is encoded UTF-8 in the HTML meta tags, but when I look inside FireBug, I see the following:
Accept-Charset ISO-8859-1,utf-8;q=0.7,*;q=0.7
I'm guessing the problem is related to the ISO-8859-1 having worked its way back in. Does anyone know why the page itself would display fine, but the text inside the javascript component wouldn't? Do you somehow specify the encoding separately for the javascript files?
The Accept-Charset tag gives a set of encodings that are accepted -- if all the data sent is encoded UTF-8, then don't worry about it.
Can you elaborate on exactly what is happening?
You say "javascript table" -- I presume you are constructing an HTML table in JS and placing it in the DOM? Please elaborate, especially w.r.t. any character conversions. Are you building HTML text or building with DOM elements with attributes?
Where does the JS get its data? If with AJAX, have you verified the Encoding for that page?
Does the JS use encode() or decode()? Those don't handle UTF-8 correctly.
EDIT:
Type the URL to the JS code in your browser, and look at "Page Info" to see its encoding. I'll bet it is ISO-8859-1, which would explain the header problems.
Next, check the encoding of the AJAX data. If it's dynamically created you can:
Enable "Show XMLHttpRequests" in FireBug's console,
Load on your base HTML page,
Open the FireBug console tab,
Expand the AJAX GET/POST request and open the Response sub-tab,
Check the Encoding for the data, and fix as needed.
BTW, I'm having similar problems and haven't entirely ironed out the issues (still not sure the source data isn't badly encoded).
It's possible that the ext. JS file strips out unrecognised characters as a security precaution.
The "Accept-Charset" header can be specified in a number of places, including as an attribute in certain HTML elements. Have you performed a search for Accept-Charset (case insensitive) in the offending file?