当前页面: 开发资料首页 → JSP 专题 → JSF中文输入乱码问题解决方法
摘要: JSF中文输入乱码问题解决方法
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片段
3、在页面使用转换器