简体   繁体   English

如何添加对字符集IBM437到J2SE 1.4 API的支持

[英]how to add support for character set IBM437 to J2SE 1.4 API

I have to make changes to an old project which uses J2SE 1.4. 我必须对使用J2SE 1.4的旧项目进行更改。 Now as I run the project I get the error 现在,当我运行项目时,我得到了错误

javax.servlet.ServletException: The character set 'IBM437' is supported by the JSE 1.1 API, but not the J2SE 1.4 API.
This requires fixing the Java Runtime Environment!
Please read the Javadoc of this error class for more information.
    at org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:498)
    at org.apache.jsp.download_orders_action_jsp._jspService(download_orders_action_jsp.java:131)
    at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:92)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:720)
    at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:162)
    at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:240)
    at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:187)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:720)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:199)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:145)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:210)
    at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:596)
    at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:433)
    at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:955)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:139)
    at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:596)
    at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:433)
    at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:955)
    at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2460)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:133)
    at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:596)
    at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:119)
    at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:594)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:116)
    at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:594)
    at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:433)
    at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:955)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:127)
    at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:596)
    at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:433)
    at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:955)
    at org.apache.coyote.tomcat4.CoyoteAdapter.service(CoyoteAdapter.java:157)
    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:873)
    at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:665)
    at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:528)
    at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:81)
    at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:689)
    at java.lang.Thread.run(Thread.java:534)

It is being used by a zip file creator. 它由zip文件创建者使用。 M question is how can I add this support to J2SE 1.4. 问题是如何将这种支持添加到J2SE 1.4。 Googling the problem got me to this page , but i dont get what to do from this page. 谷歌搜索问题让我到这个页面,但我不知道从这个页面做什么。 Any help will be greatly appreciated. 任何帮助将不胜感激。

code for making the zip files , which is being called from the jsp and where i think the real problem is 用于制作zip文件的代码,这是从jsp调用的,我认为真正的问题在于

String zipFilename = currentDumpDirName + ".zip";
de.schlichtherle.io.File srcDir = new de.schlichtherle.io.File(currentDumpRootDir);
de.schlichtherle.io.File zipFile = new de.schlichtherle.io.File(dumpRootDir, zipFilename);
boolean zippedSuccessfully = srcDir.copyAllTo(zipFile);
zipFile.umount();

as one can see from the root cause of the exception 从异常的根本原因可以看出

de.schlichtherle.io.archive.spi.AbstractArchiveDriver$InconsistentCharsetSupportError: The character set 'IBM437' is supported by the JSE 1.1 API, but not the J2SE 1.4 API. de.schlichtherle.io.archive.spi.AbstractArchiveDriver $ InconsistentCharsetSupportError:JSE 1.1 API支持字符集'IBM437',但不支持J2SE 1.4 API。 This requires fixing the Java Runtime Environment! 这需要修复Java Runtime Environment! Please read the Javadoc of this error class for more information. 有关更多信息,请阅读此错误类的Javadoc。 at de.schlichtherle.io.archive.spi.AbstractArchiveDriver.(AbstractArchiveDriver.java:92) at de.schlichtherle.io.archive.zip.Zip32Driver.(Zip32Driver.java:136) at de.schlichtherle.io.archive.zip.Zip32Driver.(Zip32Driver.java:71) at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27) at java.lang.reflect.Constructor.newInstance(Constructor.java:274) at java.lang.Class.newInstance0(Class.java:308) at java.lang.Class.newInstance(Class.java:261) at de.schlichtherle.io.ArchiveDriverRegistry.createArchiveDriver(ArchiveDriverRegistry.java:267) at de.schlichtherle.io.ArchiveDriverRegistry.getArchiveDriver(ArchiveDriverRegistry.java:240) at de.schlichtherle.io.DefaultArchiveDetector.getArchiveDriver(DefaultArchiveDetector.java:324) at de.schlichtherle.io.File.init(File.java:892) at at de.schlichtherle.io.archive.spi.AbstractArchiveDriver。(AbstractArchiveDriver.java:92)at de.schlichtherle.io.archive.zip.Zip32Driver。(Zip32Driver.java:136)at de.schlichtherle.io.archive.zip .Zip32Driver。(Zip32Driver.java:71)sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java: 27)在java.lang.Class.newInstance(Class.java:281)java.lang.Class.newInstance(Class.java:28)的java.lang.reflect.Constructor.newInstance(Constructor.java:274)中de.schlichtherle.io.ArchiveDriverRegistry.createArchiveDriver(ArchiveDriverRegistry.java:267)at de.schlichtherle.io.ArchiveDriverRegistry.getArchiveDriver(ArchiveDriverRegistry.java:240)at de.schlichtherle.io.DefaultArchiveDetector.getArchiveDriver(DefaultArchiveDetector.java:324)在de.schlichtherle.io.File.init(File.java:892)at de.schlichtherle.io.File.init(File.java:810) at de.schlichtherle.io.File.(File.java:556) at de.schlichtherle.io.File.(File.java:522) at uk.co.planetbeyond.photoprintingserver.OrdersPackagingService.packageOrders(OrdersPackagingService.java:43) at org.apache.jsp.download_orders_action_jsp._jspService(download_orders_action_jsp.java:118) at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:92) at javax.servlet.http.HttpServlet.service(HttpServlet.java:720) at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:162) at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:240) at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:187) at javax.servlet.http.HttpServlet.service(HttpServlet.java:720) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:199) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:145) at org.apache.catalina.core.StandardWrapp de.schlichtherle.io.File.init(File.java:810)at de.schlichtherle.io.File。(File.java:556)at de.schlichtherle.io.File。(File.java:522)at uk位于org.apache.jsp.download_orders_action_jsp._jspService(download_orders_action_jsp.java:118)的.co.apnetbeyond.photoprintingserver.OrdersPackagingService.packageOrders(OrdersPackagingService.java:43)org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java) :92)在javax.servlet.http.HttpServlet.service(HttpServlet.java:720)在org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:162)在org.apache.jasper.servlet.JspServlet。位于org.apache.catalina的javax.servlet.http.HttpServlet.service(HttpServlet.java:720)的org.apache.jasper.servlet.JspServlet.service(JspServlet.java:187)中的serviceJspFile(JspServlet.java:240) .core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:199)位于org.apache.catalina.core.StandardWrapp的org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:145) erValve.invoke(StandardWrapperValve.java:210) at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:596) at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:433) at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:955) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:139) at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:596) at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:433) at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:955) at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2460) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:133) at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:596) at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispa erValve.invoke(StandardWrapperValve.java:210)位于org.apache.catalina.core.StandardPipeline $ StandardPipelineValveContext.invokeNext(StandardPipeline.java:596)org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:433)在org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:955)在org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:139)在org.apache.catalina.core.StandardPipeline $ StandardPipelineValveContext .invokeNext(StandardPipeline.java:596)org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:433)org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:955)org。 apache.catalina.core.StandardContext.invoke(StandardContext.java:2460)在org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:133)在org.apache.catalina.core.StandardPipeline $ StandardPipelineValveContext.invokeNext( StandardPipeline.java:596)org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispa) tcherValve.java:119) at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:594) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:116) at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:594) at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:433) at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:955) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:127) at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:596) at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:433) at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:955) at org.apache.coyote.tomcat4.CoyoteAdapter.service(CoyoteAdapter.java:157) at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:873) at org.apache.coyote tcherValve.java:119)在org.apache.catalina.core.StandardPipeline $ StandardPipelineValveContext.invokeNext(StandardPipeline.java:594)在org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:116)在org.apache .catalina.core.StandardPipeline $ StandardPipelineValveContext.invokeNext(StandardPipeline.java:594)在org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:433)在org.apache.catalina.core.ContainerBase.invoke(ContainerBase的.java:955)在org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:127)在org.apache.catalina.core.StandardPipeline $ StandardPipelineValveContext.invokeNext(StandardPipeline.java:596)在org.apache。 catalina.core.StandardPipeline.invoke(StandardPipeline.java:433)org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:955)org.apache.coyote.tomcat4.CoyoteAdapter.service(CoyoteAdapter.java: 157)在org.apache.coyote的org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:873) .http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:665) at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:528) at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:81) at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:689) at java.lang.Thread.run(Thread.java:534) Caused by: java.nio.charset.UnsupportedCharsetException: IBM437 at java.nio.charset.Charset.forName(Charset.java:486) at de.schlichtherle.io.archive.spi.AbstractArchiveDriver.testJSE14Support(AbstractArchiveDriver.java:112) at de.schlichtherle.io.archive.spi.AbstractArchiveDriver.(AbstractArchiveDriver.java:89) ... 53 more .http11.Http11BaseProtocol $ Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:665)org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:528)org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt (LeaderFollowerWorkerThread.java:81)at org.apache.tomcat.util.threads.ThreadPool $ ControlRunnable.run(ThreadPool.java:689)at java.lang.Thread.run(Thread.java:534)引起:java。 nio.charset.UnsupportedCharsetException:位于de.schlichtherle的de.schlichtherle.io.archive.spi.AbstractArchiveDriver.testJSE14Support(AbstractArchiveDriver.java:112)的java.nio.charset.Charset.forName(Charset.java:486)中的IBM437。 io.archive.spi.AbstractArchiveDriver。(AbstractArchiveDriver.java:89)... 53更多

You appear to be using IBM437 as the canonical name or alias of the charset, and according to the same page that you linked , it is not listed as a valid name or alias. 您似乎使用IBM437作为charset的规范名称或别名,并且根据您链接同一页面 ,它未列为有效名称或别名。 Instead, IBM-437 is listed, which appears to be the right name, and you ought to specify that instead. 相反,列出了IBM-437 ,它似乎是正确的名称,您应该指定它。

I don't see any code posted in the question, that uses the String literal IBM437 in code, and going by the stacktrace I suspect that you've specified this in a JSP (which gets compiled into a Servlet that uses the Jasper engine) either in the pageEncoding attribute or in the contentType attribute of the page directive. 我没有在问题中看到任何代码,在代码中使用字符串文字IBM437 ,并且在IBM437中我怀疑你在JSP中指定了它(它被编译成使用Jasper引擎的Servlet)在pageEncoding属性或page指令的contentType属性中。 So, you ought to replace IBM437 to IBM-437 in the JSP, and recompile the same. 因此,您应该在JSP IBM437替换为IBM-437 ,并重新编译。

Also, you haven't specified whether your project must use the IBM-437 character set. 此外,您尚未指定项目是否必须使用IBM-437字符集。 I suspect that the IBM-437 character set is being used due to one of more system properties like file.encoding being set to IBM-437 . 我怀疑正在使用IBM-437字符集,因为有一个或多个系统属性,例如file.encoding被设置为IBM-437 If you do not intend to use IBM-437 , you ought to start considering use of a canonical name or alias like UTF-8 throughout your code, so that your application does not have any misplaced assumptions about the character set of the input data or output responses that it is dealing with. 如果您不打算使用IBM-437 ,您应该开始考虑在整个代码中使用规范名称或别名(如UTF-8),以便您的应用程序不会对输入数据的字符集有任何错误的假设或它正在处理的输出响应。


Updated answer 更新的答案

Based on the new stack trace and the posted code, the following could be deduced: 根据新的堆栈跟踪和发布的代码,可以推导出以下内容:

  • You are using TrueZIP 6. This is important in a way, as the underlying reason for requiring IBM437 character set support in your JRE is due to the underlying requirement of encoding file entries in a ZIP file using the IBM437 character set , also known as CP437 . 您正在使用TrueZIP 6.这在某种程度上很重要,因为在JRE中需要IBM437字符集支持的根本原因是由于使用IBM437字符集 (也称为CP437 在ZIP文件中编码文件条目基本要求。
  • Your current JRE and operating environment does not support the IBM437 character set in any form . 您当前的JRE和操作环境不支持任何形式IBM437字符集。 Note the emphasis in the previous line. 请注意前一行中的重点。 Apparently, TrueZIP 6 ships with support for IBM437 , even though the JRE may not support this character set. 显然,TrueZIP 6支持IBM437 ,即使JRE可能不支持此字符集。 TrueZIP uses the SPI provider concept in Java NIO that is available since Java 1.4 for supporting additional charsets that are not natively supported by the JRE; TrueZIP使用Java NIO中SPI提供程序概念,概念自Java 1.4以来可用于支持JRE本身不支持的其他字符集; in this particular case, the IBM437 character set is supported via the de.schlichtherle.nio.charset.IBM437Charset class that must be present in your truezip-6.jar file. 在这种特殊情况下, IBM437字符集通过必须存在于truezip-6.jar文件中的de.schlichtherle.nio.charset.IBM437Charset类来支持。 The JAR file must also contain the following file: META-INF/services/java.nio.charset.spi.CharsetProvider with the content being de.schlichtherle.nio.charset.spi.CharsetProvider (ie the charset provider embedded within TrueZIP that registers the IBM437Charset class). JAR文件还必须包含以下文件: META-INF/services/java.nio.charset.spi.CharsetProvider ,内容为de.schlichtherle.nio.charset.spi.CharsetProvider (即嵌入在TrueZIP中的charset提供程序,用于注册IBM437Charset类)。

Based on the above, you ought to verify the following: 基于以上所述,您应该验证以下内容:

  • Can the web application's class loader look up the charset provider embedded within TrueZIP? Web应用程序的类加载器是否可以查找TrueZIP中嵌入的charset提供程序? This is important, as the underlying JRE (I'm assuming it is Sun JRE 1.4.2_x) does not support the IBM437 character set, and TrueZIP relies on the embedded character set provider to support the IBM437 character set. 这很重要,因为底层JRE(我假设它是Sun JRE 1.4.2_x)不支持IBM437字符集,而TrueZIP依赖嵌入式字符集提供程序来支持IBM437字符集。 Since, CharsetProvider s are looked up using the current thread's context classloader (noted in the CharsetProvider Java API documentation), the inability to load TrueZIP's CharsetProvider will result in the InconsistentCharsetSupportError being thrown. 因为CharsetProvider是使用当前线程的上下文类加载器CharsetProvider (在CharsetProvider Java API文档中注明),无法加载TrueZIP的CharsetProvider将导致抛出InconsistentCharsetSupportError In most web applications, the current thread's context classloader also happens to be the web application's class loader (that loads classes from WEB-INF\\lib and WEB-INF\\classes ), but this is not necessarily true. 在大多数Web应用程序中,当前线程的上下文类加载器也恰好是Web应用程序的类加载器(从WEB-INF\\libWEB-INF\\classes加载WEB-INF\\classes ),但这不一定是真的。 In the event that the context classloader is not the web application classloader, you would have to place the truezip-6.jar file in the classpath of the context classloader instead of WEB-INF\\lib. 如果上下文类加载器不是Web应用程序类加载器,则必须将truezip-6.jar文件放在上下文类加载器的类路径中而不是WEB-INF \\ lib中。
  • You may verify whether the error is with loading of the TrueZIP CharsetProvider implementation, by running your code in a standalone JRE (from the commandline) instead of running it in a web-application; 您可以通过在独立的JRE( CharsetProvider运行代码而不是在Web应用程序中运行代码来验证错误是否与加载TrueZIP CharsetProvider实现有关; remember to place truezip-6.jar in the classpath of the application. 记得将truezip-6.jar放在应用程序的类路径中。
  • Consider placing truezip-6.jar in the extensions directory ( <jre>/lib/ext ) of the JRE used by the web-application's container. 考虑将truezip-6.jar放在Web应用程序容器使用的JRE的扩展目录( <jre>/lib/ext )中。 This ought to be attempted only if you are unable to get the current thread's context classloader to load the TrueZIP CharsetProvider , and only when you've verified that the problem is with loading the CharsetProvider . 只有当您无法获取当前线程的上下文类加载器来加载TrueZIP CharsetProvider ,才应该尝试这种CharsetProvider ,并且只有当您确认问题是加载CharsetProvider

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

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