非法字符 - CTRL-CHAR [英] Illegal character - CTRL-CHAR

查看:4059
本文介绍了非法字符 - CTRL-CHAR的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从网络服务获取以下exceptopn:

I am getting following exceptopn from webservices:


com.ctc.wstx.exc.WstxUnexpectedCharException:非法字符,code 15))

com.ctc.wstx.exc.WstxUnexpectedCharException: Illegal character ((CTRL-CHAR, code 15))

我知道背后的原因,我得到控制字符
和在xml中CTRL-CHAR不允许。

I know the reason behind this, I am getting "Control Characters" in data I want to return. And in xml CTRL-CHAR are not allowed.

我搜索的解决方案,许多地方,我发现代码删除 CTRL-CHAR

I searched for the solution, and many places I found the code to remove CTRL-CHAR.

关注的是,如果我从数据中删除控制字符,我最终会失去数据?
我想要的清洁解决方案可能编码。而不是删除控制字符。

The concern is shall I end up loss of data if I remove control characters from data? I want the clean solution may encoding. Instead of removing control char.

推荐答案

感谢你的输入。我分享的解决方案可能对其他人有帮助。
该要求不是清除CONTROL CHAR,它应该保持在DB中,并且一个WS发送它在n / w客户端应该能够获得CONTROL CHAR。所以我实现代码如下:

Thanks guys for you inputs. I am sharing solution might be helpful for others. The requirement was not to wipe out CONTROL CHAR, it should remain as it is in DB also and one WS sends it across n/w client should able to get the CONTROL CHAR. So I implemented the code as follow:


  1. 在Web服务代码中使用URLEncoder编码字符串。

  2. 在客户端使用URLDecoder解码

共享示例代码和输出波形。 >
示例代码:

Sharing sample code and output bellow.
Sample code:

System.out.println("NewSfn");  
System.out.println(URLEncoder.encode("NewSfn", "UTF-8"));  
System.out.println(URLDecoder.decode("NewSfn", "UTF-8"));  

输出

NewSfn  
New%0FSfn  
NewSfn 


$ b b

因此,客户将收到CONTROL CHAR。

So client will recieve CONTROL CHARs.

编辑:Stack Exchange上面没有显示CONTROL CHAR。 NewSfn 就像这样新(CONTROL CHAR)Sfn

Stack Exchange is not showing CONTROL CHAR above. NewSfn is like this New(CONTROL CHAR)Sfn.

这篇关于非法字符 - CTRL-CHAR的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆