English 中文(简体)
• 如何将UTF-8混为一谈?
原标题:How to configure UTF-8 on Velocity?

利用 Java、塞莱、MySQL、Tomcat和Velocity采取了以下步骤:

  • velocity.properties :
    • input.encoding=UTF-8
    • output.encoding=UTF-8
  • server.xml
    • URIEncoding = UTF-8
  • <html><head> Charset
    • meta http-equiv="Content-Type" content="text/html;CHARSET=UTF-8"
  • eclipse properties, project properties, file & editor encoding
    • set all that apply to UTF-8
  • JDBC connection:
    • db.url=jdbc:mysql://:/?useEncoding=true&characterEncoding=UTF-8
  • java/servlet code:
    • request.setCharacterEncoding( UTF-8 )

上述所有工作都是徒劳的。 在以下法典出台之前:

private String getParameter(String key) {
    String param = request.getParameter(key);
        if (Util.isNotEmpty(param)) {
            try {
                return new String(param.getBytes("8859_1"), "utf-8");
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
            }
            return param;
        }
    return null;
}

以上意思是,<代码>request.setCharacterEncoding don t有效力(getCharacterEncoding()确实将UTF-8 退回;明知该请求的总结载于; 当地人物体。

How is this caused and how can I solve it?

问题回答

To interpret parameters correctly, the URL needs to be parsed as UTF-8 by tomcat. Set this in the server.xml connector properties, e.g. with:

<Connector port="8080"
               maxThreads="150" minSpareThreads="25" maxSpareThreads="75"
               enableLookups="false" redirectPort="8443" acceptCount="100"
               debug="0" connectionTimeout="20000" 
               disableUploadTimeout="true" 
               URIEncoding="UTF-8"/>

您在浏览器发现K的编码中得到了参数。 但是,问题可能基于一个超编的浏览器配置或Xml头er <?xml edition=“1.0” encoding=“iso8895_1”?>如果这种超文本与正编码一致,则可能需要什么。





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...