输入中文,然后在输出,显示为乱码解决方法
来源:互联网 发布:淘宝店铺异常,状态码-2 编辑:程序博客网 时间:2024/06/13 10:44
inputtext中输入中文,然后在输出,显示为乱码。
解决方法:
1、自定义转器
package util;
import java.util.Map;
import javax.faces.component.UIComponent;
import javax.faces.convert.Converter;
import javax.faces.context.FacesContext;
import javax.faces.convert.ConverterException;
public class StringConverter implements Converter {
public Object getAsObject(FacesContext context, UIComponent component,
String newValues) throws ConverterException {
String newstr = "";
if (newValues == null) {
newValues = "";
}
byte[] byte1 = null;
try {
byte1 = newValues.getBytes("ISO-8859-1");
newstr = new String(byte1, "GB2312");
UIInput input=(UIInput)component;//
input.setSubmittedValue(newstr);
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
return newstr;
}
public String getAsString(FacesContext context, UIComponent component,
Object Values) throws ConverterException {
return (String) Values;
}
}
2、注册转换器
faces-config.xml片段
<converter>
<converter-id>util.stringconverter</converter-id>
<converter-class>util.StringConverter</converter-class>
</converter>
3、在页面使用转换器
<h:inputText id="account" value="#{util.account}" required="true" styleClass="input" >
<f:converter converterId="utilstringconverter"/>
解决方法:
1、自定义转器
package util;
import java.util.Map;
import javax.faces.component.UIComponent;
import javax.faces.convert.Converter;
import javax.faces.context.FacesContext;
import javax.faces.convert.ConverterException;
public class StringConverter implements Converter {
public Object getAsObject(FacesContext context, UIComponent component,
String newValues) throws ConverterException {
String newstr = "";
if (newValues == null) {
newValues = "";
}
byte[] byte1 = null;
try {
byte1 = newValues.getBytes("ISO-8859-1");
newstr = new String(byte1, "GB2312");
UIInput input=(UIInput)component;//
input.setSubmittedValue(newstr);
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
return newstr;
}
public String getAsString(FacesContext context, UIComponent component,
Object Values) throws ConverterException {
return (String) Values;
}
}
2、注册转换器
faces-config.xml片段
<converter>
<converter-id>util.stringconverter</converter-id>
<converter-class>util.StringConverter</converter-class>
</converter>
3、在页面使用转换器
<h:inputText id="account" value="#{util.account}" required="true" styleClass="input" >
<f:converter converterId="utilstringconverter"/>
- 输入中文,然后在输出,显示为乱码解决方法
- jsp显示中文为乱码的解决方法
- JS文件中的中文在网页上显示为乱码解决方法
- 直接在xampp中的mysql中操作时输入中文,然后保存,此时中文变为乱码
- jmeter body data,输入中文显示为乱码,如何解决
- eclipse中集成了weblogic10.3.5,然后控制台启动weblogic,中文显示乱码的解决方法
- Netbeans IDE 项目里显示的中文为乱码 解决方法
- Zabbix显示中文或图片为乱码--解决方法
- oracle-PL/SQL显示中文时为乱码的解决方法
- CodeBlocks在win7终端输出中文乱码的解决方法
- Codeblock输入中文乱码解决方法
- CGI输出中文乱码解决方法
- AS4在Terminal下中文显示乱码的解决方法
- Weblogic: 在weblogic8.1中显示中文乱码的解决方法
- eclipse中文输出为乱码
- pycharm输出中文为乱码
- 用记事本手写一个.jsp文件,然后在网页中打开中文显示乱码的解决方案
- SQL2000中文显示乱码解决方法
- FreeMarker初级攻略
- JSF参数传递方式
- OOM(out_of_memory) killer分析
- 设计模式之五S:动态代理模式(Dynamic Proxy Pattern)
- 算法:队列与广度优先搜索(迷宫问题)
- 输入中文,然后在输出,显示为乱码解决方法
- Android的设计与实现:卷I
- asp.net 错误编号的意义(400,500)
- is not in the sudoers file. This incident will be reported
- linux上 管理arp的一些工具
- 创建和使用Android Library工程
- java.lang.ClassCastException: cn.vlabs.csp.model.expotion.ExpoFeeConfig cannot be cast to java.lang.
- Java开发规范使用手册
- java 杂七杂八