Skip to main content

Posts

Showing posts with the label character-encoding

Java: Why charset names are not constants?

Charset issues are confusing and complicated by themselves, but on top of that you have to remember exact names of your charsets. Is it "utf8" ? Or "utf-8" ? Or maybe "UTF-8" ? When searching internet for code samples you will see all of the above. Why not just make them named constants and use Charset.UTF8 ?

Respond encoding of Google App Engine(can not change response encoding)

public class FeedUpdaterServlet extends HttpServlet { public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException { PrintWriter out = resp.getWriter(); req.setCharacterEncoding("utf-8"); resp.setLocale(Locale.TAIWAN); resp.setContentType("text/html; charset=utf-8"); resp.setCharacterEncoding("utf-8"); resp.getWriter().println("Hello, world!!@!"); out.println("我是人"); //some chinese character out.println(resp.getCharacterEncoding()); out.flush(); out.close(); } } web xml <locale-encoding-mapping-list> <locale-encoding-mapping> <locale>zh_TW</locale> <encoding>utf-8</encoding> </locale-encoding-mapping> </locale-encoding-mapping-list> Output: Hello, world!!@! ??? ISO-8859-1 It seems that the encoding of the respond can not be changed, what is happening???

strange characters(?) added to the end of my subject text

I have a problem with my java code sending email to users. There is some problem with the encoding of the email. When the email arrives to email account the subject line ($subject) has encoding problems as has strange characters(?) added to the end of my subject text. The email message content itself is fine just the subject line(?) I have searched all over but cant find,after using Unicode and content type as text/html mail body have no problem with special character ( ó ) but same fix is not working for subject line. I have a class that sends an email with javamail, with a text like this one in subject : "Estimado Iván Escobedo: The problem is that when the mail arrives to its destination, it arrives this way: "Estimado Iv?n Escobedo: All the á , é , í , ó , ú , etc special characters are replaced with ? . What could be the problem and how to solve it?

How to make simplest servlet filter respect setted character encoding

Gentlemen, it feels like I'm stuck. I'm trying to write the simplest servlet Filter (and deploy it to tomcat). It's a groovy code, but actually I'm heavily usin java approaches here, so it is almost copypaste, that's the reason I've added java tag as well. My question is - how can I insert UTF-8 string to filter? Here is the code: `public class SimpleFilter implements javax.servlet.Filter { ... public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws java.io.IOException, javax.servlet.ServletException { PrintWriter out = response.getWriter() chain.doFilter(request, wrapResponse((HttpServletResponse) response)) response.setCharacterEncoding('UTF-8') response.setContentType('text/plain') def saw = 'АБВГДЕЙКА ЭТО НЕПРОСТАЯ ПЕРЕДАЧА ABCDEFGHIJKLMNOP!!!' def bytes = saw.getBytes('UTF-8') def content = new String(bytes,

JCharset not being recognized in browser

I am working on a simple email client using a Java applet. I am getting the exception "java.io.UnsupportedEncodingException: utf-7" when I open certain emails. I have added JCharset, and that fixes the issue when I run the applet in NetBeans' applet viewer, but when I run it in a browser I get the same exception. I have added the necessary file "java.nio.charset.spi.CharsetProvider" to META-INF/services, which is in my src directory. What else do I need to do to get it to recognize it when I run it in the browser?