编程语言
首页 > 编程语言> > java-JSF和HTML表单的Unicode问题?

java-JSF和HTML表单的Unicode问题?

作者:互联网

我有一个由JSF生成的HTML表单,该表单将输入元素映射到bean setter
在我看来,JSF正在将Unicode输入加为非法.特别是,我在setter中放置了以下异常以进行测试

public void setTitle(String title){
    System.out.println("title set with: "+title+"\n");
    if (title.startsWith("xxx")) {
        throw new RuntimeException("debug exception "+title);
    }
    this.title = title;
}

然后,将以下文本放入表单标题输入元素:“ xxxx海陆”.然后,当我提交表格时,我会看到日志打印

title set with: xxxx ????? 

(在与unicode兼容的mac终端上).
而且我在响应HTML页面上收到一条错误消息:

Error setting property 'title' in bean of type   
uk.ac.lancs.e_science.sakaiproject.api.blogger.post.Post: 
java.lang.RuntimeException: debug exception xxxx ���??

有什么问题的线索吗?我只是装满了,诊断错误吗?
我想我已经消除了所有其他可能性. Unicode似乎可以在同一应用程序的其他组件中正常工作.

解决方法:

我会问的问题:

>表单如何编码请求(application / x-www-form-urlencoded或multipart / form-data)?多部分数据将使用第三方MIME解析器进行解码,因此存在麻烦的余地.如果数据经过url编码,是否可以正确转义?
>浏览器accepting是什么字符集?
>什么encoding is the server detecting?它是Unicode字符集吗?
>只是将日志记录为lossy encoding(例如MacRoman)吗?服务器正在使用什么default charset

由于在控制台上看到的不一定是字符串中的内容,因此可以使用以下代码转储Unicode code points

  public static void printCodepoints(char[] s) {
    for (int i = 0; i < s.length; i++) {
      int codePoint = Character.isHighSurrogate(s[i]) ? Character
          .toCodePoint(s[i], s[++i])
          : s[i];
      System.out.println(Integer.toHexString(codePoint));
    }
  }

标签:unicode,jsf,html,java
来源: https://codeday.me/bug/20191210/2103066.html