简体   繁体   English

Oracle驱动程序行为异常Tomcat 6.0

[英]Oracle driver misbehavior Tomcat 6.0

I have a Tomcat 6.0 Application server, with a pretty simple web applcation using an oracle connection. 我有一台Tomcat 6.0 Application Server,具有使用oracle连接的非常简单的Web应用程序。 The connection itself is defined in the server.xml file as a JDBCRealm. 连接本身在server.xml文件中定义为JDBCRealm。

The default encoding of the server is latin1. 服务器的默认编码为latin1。 The database encoding is UTF-8. 数据库编码为UTF-8。 Normally everything works fine, special characters get inserted in the databse as the should and the are retrieved in proper encoding. 通常情况下一切正常,特殊字符会按应有的方式插入数据库,并以正确的编码进行检索。 If I'm not mistaking this is because the Oracle driver resolves any encoding mismatches automatically. 如果我没有记错的话,这是因为Oracle驱动程序会自动解决所有编码不匹配的问题。

I added the following bit to the catalina.bat file where the AS starts up, to set the encoding that is to be used for Catalina: 我在启动AS的catalina.bat文件中添加了以下位,以设置用于Catalina的编码:

-Dfile.encoding=UTF-8

Now I can still save special characters like ŰÁÉÚŐÖÜÓ , and they are inserted like this in the database, but if I reload the data on some page the encoding is all messed up. 现在,我仍然可以保存诸如ŰÁÉÚŐÖÜÓ类的特殊字符,并且将其像这样插入数据库中,但是如果我在某些页面上重新加载数据,则编码将全部混乱。 Something like: ĂĂĂĂĂĂĂĂ . 像: ĂĂĂĂĂĂĂĂ

So I can still insert, but I can't get data in correct format after I add that line. 因此,我仍然可以插入,但是添加该行后无法获得正确格式的数据。 Does anyone have any idea how to resolve this issue? 有谁知道如何解决这个问题? Or what could maybe cause it? 或可能是什么原因造成的? I need this setup because I'm actually trying to recreate an error on another environment. 我需要此设置,因为我实际上正在尝试在另一个环境上重新创建错误。

Well, I kind of figured out what the problem is. 好吧,我有点想出了问题所在。 I blamed the oracle driver for not doing the conversion right. 我指责oracle驱动程序没有正确执行转换。 However the servlet transmitted the values in a wrong format to start with, and displayed them in an even worse fashion. 但是,该servlet最初以错误的格式传输值,并以更差的方式显示它们。 So the actual simple solution was to extend the was xml with a general filter referencing a commonly used encoding fitler, that is also present in the tomcat folder's eaxmple webapps. 因此,实际的简单解决方案是使用通用过滤器扩展was xml,该过滤器引用了常用的编码拟合器,该过滤器也存在于tomcat文件夹的eaxmple webapps中。 I added this to web.xml: 我将此添加到web.xml:

<filter>
    <filter-name>Set Character Encoding</filter-name>
    <filter-class>filters.SetCharacterEncodingFilter</filter-class>
    <init-param>
        <param-name>encoding</param-name>
        <param-value>UTF-8</param-value>
    </init-param>
</filter>
<filter-mapping>
    <filter-name>Set Character Encoding</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>

And all got well! 一切都很好! This will be pretty much the first thing I add to a web.xml from now on. 从现在开始,这几乎是我添加到web.xml中的第一件事。 Thanks a lot anyways, Cheers! 无论如何,非常感谢,干杯!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM