<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets" >
<head>
</head>
<h:form>
<h:body>
<h:inputText value="#{editorBean.value2}" />
<h:commandButton action="content.xhtml" value="Submit" />
</h:body>
</h:form>
</html>
- 值 2 是 session 范围 ManageBean 中的字符串
- 使用 JSF Mojarra 2.1.19
- Glassfish 3.1.2
当我输入 äüö
并提交表单时,它在 stdout 中显示为 Á¤à¶ū
。
但是如果我使用ajax,则不会发生这种情况。
这是怎么造成的,如何解决?
最佳答案
JSF/Facelets 在整个过程中默认使用 UTF-8。
您只需告诉 Glassfish 请求参数是使用 UTF-8 编码的,这样它就会使用 UTF-8 正确解码。打开/WEB-INF/glassfish-web.xml
文件并将以下条目添加到 <glassfish-web-app>
:
<parameter-encoding default-charset="UTF-8" />
顺便说一句,你的<h:form>
必须进入<h:body>
内部 ,不在外面。另外,您应该使用 <h:head>
而不是<head>
为了让 JSF 自动包含正确的 Ajax 脚本。
关于jsf - 向托管 bean 发送 UTF-8 字符串不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10915077/