很奇怪的问题,我在一个类文件里的某个方法里调用dll的方法乱码,但是我在同样的类文件里直接在main方法里调用dll的方法就显示正常。这个dll是控制显示器的。
如:
- Java code
public class TestServiceImpl{ public boolean service(){ // xxx 得到下面方法AddTextArea的参数,其中text是中文的,①调用了instance.AddTextArea方法后,显示器就会显示这个text的文字,此处调用会显示乱码 int reslut = instance.AddTextArea(jno, qno, left,top, width, height, fontColor, fontName,fontSize, fontBold, fontItalic, fontUnder,line, hAlign, vAlign, text, type, speed, delay); // 省略 } public static void main(String[] args){ // ②此处调用则显示正常 int reslut = instance.AddTextArea(jno, qno, left,top, width, height, fontColor, fontName,fontSize, fontBold, fontItalic, fontUnder,line, hAlign, vAlign, text, type, speed, delay); }}
①处是把整个项目在tomcat里跑起来,然后action会调用这个service的方法,显示乱码。
②处是直接在这个类的main方法里运行,中文显示正常。
------解决方案--------------------------------------------------------
2个环境的编码格式不一样!
------解决方案--------------------------------------------------------
建议把项目导出成war包,再部署,我有遇到过同样的问题。