Display chinese characters in AJAX and also in excel

I am currently developing a Java Struts application and i been wondering how is it possible to display chinese characters in AJAX and also when generating excel file by servlet response.

Anyone can share any pointers?

Asked by: Grace177 | Posted: 28-01-2022

Answer 1

As long as you use UTF8 for your character encoding, I think you should be fine. If UTF8 is not an option, and you're going to display only Chinese, you can even try one of the Chinese specific character encodings.

I'll try and get you more details, but at the very least, to set the character encoding, you'll have to do:



response.setContentType("text/plain; charset=UTF-8");

Refer to the Java EE Specs (http://java.sun.com/j2ee/1.4/docs/api/index.html) for what these mean exactly.

Answered by: Carina733 | Posted: 01-03-2022

Similar questions

java - Unable to display Chinese characters in excel using CSV Bean Writer

I am using ICsvBeanWriter to export data as CSV and i am trying to open it in Excel.But I am unable to view Chinese characters in Excel by default.But if i load the csv file and change encoding from Western European to 65001 Unicode(UTF-8) then i am able to see Chinese characters displayed in excel.So my question is "Is it possible to open excel with default UTF-8 encoding? Here is my code Controller.ja...

java - Display the number of the characters in a string

I have a Java question: I am writing a program to read a string and display the number of characters in that string. I found some example code but I don't quite understand the last part - can anyone help? int[] count = countLetters(line.toLowerCase()); for (int i=0; i<count.length; i++) { if ((i + 1) % 10 == 0) System.out.println( (char) ('a' + i)+ " " + count[i]); else Syste...

java - Display unicode characters in android?

I've created a messaging app and am learning a good portion of members don't reside in North America or the UK. When they post messages only garbled text is returned. All database columns where the data is store is in UTF-8. Is there a way to properly display UTF-8 Characters that someone has been able to enter? See the screenshot below.

java - Not able to display special characters

I am unable to display special characters (polish characters) on screen. I have a requirement where I get the data from database which has some special characters. I get the data in an xml format (The xml is not recognizing it as a string) and pass it to action where I try to display the data. I am trying to get the Uniciode of the special character as ł but when I try to display, this gets convert...

java - OSGi bundle doesn't display utf-8 characters

In my Bundle, I'm trying to display utf-8 characters, I suppose my default charset is Cp1250 and strange behaviour happens: public class Activator implements BundleActivator { public void start(BundleContext context) throws Exception { System.out.println("ąśżłóę"); // this is what should've been displayed System.out.println("������"); // this is the utf8 above encoded ...

characters display of a text file in java

Closed. This question needs details or clarity. It ...

utf 8 - unable to display latin characters using java

i'm using the following lines of code to read the data frm db ob = new String(loadBlob.toByteArray()); ob = Util.decrypt(Constants.ENCRYPTION_KEY, ob); ob = new String(Base64.decodeBase64(ob.getBytes("UTF-8")), "UTF-8"); but while displaying the latin characters appears as a box. even in db proper characters are available.

java - display special characters in jsp page

How to display right content on jsp page or any configuration need to done in tomcat server...? display at jsp : Hello G�nter original content : Hello Günter We do the following but its not working. <%@ page language="java" contentType="text/html; charset=ISO-8859-15" pageEncoding="UTF-8"%>

Display unicode characters in Java

I tried to display some unicode characters in the range Sinhala (80: 0D80–0DFF) in java swing components. Those letters are displayed correctly in eclipse console, but those are shown as boxs in JButtons , JTextArea, JTextPane & etc. import java.awt.BorderLayout; import javax.swing.*; public class Unicode extends JFrame{ public Unicode(){ super("ක් කැ කැ කු අ ඉ"); ...

java - Display special characters in page

I'm having one div which will display some text. I'm getting this text from DB. This text can contains special characters like "\",">","<" etc. When I'm trying to display this text in my page, these special characters wont be visible in my page for obvious reasons. So how to handle this situation.

java - How to display strange characters in Android

Could someone shed me light on why strange characters does not appear in Android listView? I have a text file with this And I got this Here is my code ArrayList<String> list = new ArrayList<S...

Setting unicode characters in java frames

How to display unicode characters (e.g. japanese) in the title of a JFrame in java swing in a Windows XP m/c without the Japanese language pack? It looks like setting the title text to Japanese unicode characters and the font to MS Mincho is not enough. While this is all you need to do to display unicode characters in Swing labels?

java - Escaping Special Characters Posted to Servlet

I have a jsp containing a form which posts to a servlet, when the servlet receives the parameters from the form the pound sign (£) is preceded with the following character Â. So £ becomes £. What is causing this and how can I get round it?

java - Using unicode characters

I have a problem with unicode. I have a multi-language project. When I enter the data in the local language, in Access the data is stored something like this as " ಅಮà³à²®" but I want those characters of the local language to be seen at the back end. Ccould you please suggest how to do this? I'm using Java, Windows vista, and ms-access. I had set database encoding using properties class and p...

java - How can I escape special HTML characters in JSP?

Before I go and create a custom tag or Java method to do it, what is the standard way to escape HTML characters in JSP? I have a String object and I want to display it in the HTML so that it appears to the user as is. For example: String a = "Hello < World"; Would become: Hello < World

Putting char into a java string for each N characters

I have a java string, which has a variable length. I need to put the piece "<br>" into the string, say each 10 characters. For example this is my string: `this is my string which I need to modify...I love stackoverlow:)` How can I obtain this string?: `this is my<br> string wh<br>ich I nee<br>d to modif<br>y...I l...

java - replace a set of characters with another set of chars (in pair): "&", "&amp;" "<", "<" etc. in regex

I have to encode the 5 XML reserved chars (&amp; &lt; > " and ') properly as follows: "&amp;", "&amp;amp;" "&lt;", "&amp;lt;" "&gt;", "&amp;gt;" "\"", "&amp;quot;" "\'", "&amp;apos;" I can do them one by one, but is it possible in regexp something like ("[&amp;|&lt;|>|\"|\']", "&amp;|&lt;"); ... etc so that it will not be executed in 5 operations one after another but alltogether simult...

Remove end of line characters from Java string

I have string like this "hello java book" I want remove \r and \n from String(hello\r\njava\r\nbook). I want the result to be "hellojavabook". How can I do this?

How can I find repeated characters with a regex in Java?

Can anyone give me a Java regex to identify repeated characters in a string? I am only looking for characters that are repeated immediately and they can be letters or digits. Example: abccde &lt;- looking for this (immediately repeating c's) abcdce &lt;- not this (c's seperated by another character)

regex - Java Pattern to match any sequence of characters except a given list

How do I write a Pattern (Java) to match any sequence of characters except a given list of words? I need to find if a given code has any text surrounded by tags like besides a given list of words. For example, I want to check if there are any other words besides "one" and "two" surrounded by the tag . "This is the first tag &lt;span&gt;one&lt;/span&gt; and this is the third &lt;span&gt;three&lt;/sp...

java - Using hibernate criteria, is there a way to escape special characters?

For this question, we want to avoid having to write a special query since the query would have to be different across multiple databases. Using only hibernate criteria, we want to be able to escape special characters. This situation is the reason for needing the ability to escape special characters: Assume that we have table 'foo' in the database. Table 'foo' contains only 1 field, called 'name'. The 'name...

Still can't find your answer? Check out these amazing Java communities for help...

Java Reddit Community | Java Help Reddit Community | Dev.to Java Community | Java Discord | Java Programmers (Facebook) | Java developers (Facebook)