国产探花免费观看_亚洲丰满少妇自慰呻吟_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"/>

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 广安市| 乌拉特中旗| 武功县| 襄城县| 安塞县| 太仆寺旗| 措美县| 莫力| 东方市| 临桂县| 安顺市| 启东市| 房产| 南城县| 绥阳县| 施甸县| 佛教| 邢台市| 东阳市| 斗六市| 搜索| 松桃| 万载县| 柳林县| 文山县| 赞皇县| 二手房| 平安县| 玉山县| 天峻县| 威远县| 固原市| 布尔津县| 南汇区| 新沂市| 永新县| 马公市| 麦盖提县| 孝感市| 福安市| 耿马|