`

websphere报错can't declare any more prefixes in this context

 
阅读更多

现象JSP里引用C标签时报 java.lang.IllegalStateException: can't declare any more prefixes in this context,但在tomcat下没问题

原因:jdom/dom4j在解释xml时,用的是ibm的jre 1.4.1时,如果xml文件中有xmlns:udm时,就会在将string input stream转成document时出现:java.lang.IllegalStateException: can't declare any more prefixes in this context错误,如果用sun的jdk1.4.2就没这个问题.是由于xml parser: Crimson不能解释带有类似于xmlns:xsi这样的属性.要用Xerces才行,但是IBM的jre在默认情况下寻找Crimson作为parser

解决办法:是通过在程序中设定jre的xml parser为Xerces,同时将Xerces的jar包加入到classpath中,一共有三个包:xalan.jar,xercesImpl.jar,xml-apis.jar

http://xml.apache.org/xalan-j/上可以下载.

http://xerces.apache.org/xerces-j/
jre的xml parser设置:是jrelib下的一个叫jaxp.properties文件,最后有三行是关于指定 xml parser的,将注释去掉,或者在程序中加入以下语句也可以:
System.setProperty("javax.xml.parsers.DocumentBuilderFactory","org.apache.xerces.jaxp.DocumentBuilderFactoryImpl");
System.setProperty("javax.xml.parsers.SAXParserFactory","org.apache.xerces.jaxp.SAXParserFactoryImpl");

如下链接中的文章解释得非常具体:
http://www.javaworld.com.tw/jute/post/view?bid=19&id=14958&sty=3

注:JSTL标签在哪涉及到了xml的解析,这里有待研究

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics