国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發 > 綜合 > 正文

JSF中文輸入亂碼問題解決方法

2024-07-21 02:15:09
字體:
來源:轉載
供稿:網友
該方法已知適用的版本tomact5.0.18,tomcat5.0.9。
已知不適用的版本為tomcat5.0.28。
問題描述:
在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"/>

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 酒泉市| 临邑县| 巴青县| 元阳县| 望都县| 额尔古纳市| 哈密市| 乐陵市| 社会| 兴业县| 山东省| 株洲市| 沙湾县| 昌黎县| 厦门市| 甘洛县| 怀安县| 府谷县| 沐川县| 临沧市| 墨竹工卡县| 满城县| 申扎县| 多伦县| 新平| 乐业县| 嘉义市| 平顺县| 图们市| 台江县| 正镶白旗| 建平县| 延川县| 临武县| 靖远县| 元阳县| 张家口市| 喀喇沁旗| 巴塘县| 米易县| 房产|