org.jdom.IllegalDataException: The dataXXX is not legal for a JDOM attribute: 0x

遇到了非法的XML字符报错如下:

 

 

org.jdom.IllegalDataExceptionThe data "现状压缩后再上传" is not legal for a JDOM attribute: 0xb is not a legal XML character. at org.jdom.Attribute.setValue(Attribute.java:486) at org.jdom.Attribute.(Attribute.java:229) at org.jdom.Attribute.(Attribute.java:252) at org.jdom.Element.setAttribute(Element.java:1109) at weaver.common.util.taglib.SplitPageXmlServlet.getXml(SplitPageXmlServlet.java:331) at weaver.common.util.taglib.SplitPageXmlServlet.doPost(SplitPageXmlServlet.java:197) at javax.servlet.http.HttpServlet.service(HttpServlet.java:153) at javax.servlet.http.HttpServlet.service(HttpServlet.java:91) at com.caucho.server.dispatch.ServletFilterChain.doFilter(ServletFilterChain.java:103) at com.caucho.server.webapp.WebAppFilterChain.doFilter(WebAppFilterChain.java:175) at com.caucho.server.dispatch.ServletInvocation.service(ServletInvocation.java:240) at com.caucho.server.http.HttpRequest.handleRequest(HttpRequest.java:263) at com.caucho.server.port.TcpConnection.run(TcpConnection.java:481) at com.caucho.util.ThreadPool$Item.runTasks(ThreadPool.java:685) at com.caucho.util.ThreadPool$Item.run(ThreadPool.java:607) at java.lang.Thread.run(Thread.java:595)

 

解决办法:

将非法字符替换掉

//如果捕获到异常则替换其中的oxb
catch(org.jdom.IllegalDataException e) {
	//e.printStackTrace();
	char [] xmlChar = paragraph.toCharArray();
    for (int i=0; i < xmlChar.length; ++i) {
	if (xmlChar[i] > 0xFFFD) 
	{ 
	   //直接替换掉0xb 
	    xmlChar[i] =' ';
	} 
	else if (xmlChar[i] < 0x20 && xmlChar[i] != 't' & xmlChar[i] != 'n' & xmlChar[i] != 'r')
	{
	   //直接替换掉0xb
	    xmlChar[i] =' ' ;
	}
    }
}
 

你可能感兴趣的:(java,thread,xml,servlet)