<dfn id="w48us"></dfn><ul id="w48us"></ul>
  • <ul id="w48us"></ul>
  • <del id="w48us"></del>
    <ul id="w48us"></ul>
  • Struts中文問題怎么解決

    時間:2024-09-09 12:07:14 SUN認證 我要投稿
    • 相關推薦

    Struts中文問題怎么解決

      碰到struts中文問題時,JSP頁面上仍然顯示的是亂碼,下面方法在windows的weblogic8下,和unix的weblogic8下均正確顯示漢字。一起來看看吧!

      以下是代碼內(nèi)容:

      首先是JSP頁面的內(nèi)容,最簡化的一個form

      TestItem English :

      TestItem Chinese :

      注意,頁面的字符集一定要定義成gb2312,否則顯示不了正確的漢字了,代碼上半部的logic:iterate 標簽是 action 處理完畢后,返回給頁面顯示的。至于form提交的部分,由struts機制去做了,我只把 testitem_config 這個 action 的原代碼給出,大家就看明白了:

      public class TestItemConfigAction extends Action {

      public ActionForward execute(ActionMapping mapping, ActionForm form,

      HttpServletRequest request, HttpServletResponse response)throws Exception {

      TestItemConfigForm pcForm = (TestItemConfigForm)form;

      String[] entryIndexArray = pcForm.getEntrypro();

      String testPartKey;

      ArrayList testPartOptionsEn = new ArrayList();

      ArrayList testPartOptionsCn = new ArrayList();

      ServletContext context = getServlet()。getServletContext();

      String file = context.getRealPath(“/WEB-INF/classes/resource/TestItem.properties”);

      PropertiesFileOperate pOperate = new PropertiesFileOperate(file);

      Properties property = pOperate.getProperties();

      int testpartnum = Integer.parseInt(property.getProperty(“test.item.num”));

      if(pcForm.getOperateFlag() != null && !“”。equals(pcForm.getOperateFlag())) {

      if(Integer.parseInt(pcForm.getOperateFlag()) == 1 &&

      pcForm.getTestItemEn() != null && !“”。equals(pcForm.getTestItemEn())){

      String addKeyEn = “test.item.en.” + (testpartnum + 1);

      String addKeyCn = “test.item.cn.” + (testpartnum + 1);

      String addValueEn = pcForm.getTestItemEn()。trim();

      String addValueCn = pcForm.getTestItemCn()。trim();

      String addValueCnWirite = new String(addValueCn.getBytes(“ISO-8859-1”));

      pOperate.modifyProperties(“test.item.num”, (testpartnum + 1) + “”);

      pOperate.addProperties(addKeyEn, addValueEn);

      pOperate.addProperties(addKeyCn, addValueCnWirite);

      pOperate.saveFile();

      pOperate = null;

      }

      if(Integer.parseInt(pcForm.getOperateFlag()) == 2 &&

      pcForm.getTestItemEn() != null && !“”。equals(pcForm.getTestItemEn())){

      int entryIndex = Integer.parseInt(pcForm.getTestItemIndex()。trim());

      String addKeyEn = “test.item.en.” + entryIndex;

      String addKeyCn = “test.item.cn.” + entryIndex;

      String addValueEn = pcForm.getTestItemEn()。trim();

      String addValueCn = pcForm.getTestItemCn()。trim();

      String addValueCnWirite = new String(addValueCn.getBytes(“ISO-8859-1”));

      pOperate.modifyProperties(addKeyEn, addValueEn);

      pOperate.modifyProperties(addKeyCn, addValueCnWirite);

      pOperate.saveFile();

      pOperate = null;

      }

      if(Integer.parseInt(pcForm.getOperateFlag()) == 3){

      for(int i = 0; i 《 entryIndexArray.length; i++){

      String indexEntry = (entryIndexArray[i]。substring(1, entryIndexArray[i]。indexOf(“,”)))。trim();

      String addKeyEn = “test.item.en.” + indexEntry;

      String addKeyCn = “test.item.cn.” + indexEntry;

      pOperate.modifyProperties(addKeyEn, “”);

      pOperate.modifyProperties(addKeyCn, “”);

      }

      pOperate.saveFile();

      pOperate = null;

      }

      }

      PropertiesFileOperate pOperateShow = new PropertiesFileOperate(file);

      Properties propertyShow = pOperateShow.getProperties();

      int testpartNumber = Integer.parseInt(propertyShow.getProperty(“test.item.num”));

      ArrayList array = new ArrayList();

      for(int i = 1; i 《= testpartNumber; i++){

      ArrayList arr = new ArrayList();

      testPartKey = “test.item.en.”+i;

      if (propertyShow.getProperty(testPartKey) != null &&

      !“”。equals(propertyShow.getProperty(testPartKey))){

      arr.add(i+“”);

      testPartOptionsEn.add(propertyShow.getProperty(testPartKey));

      arr.add(propertyShow.getProperty(testPartKey));

      testPartKey = “test.item.cn.”+i;

      testPartOptionsCn.add(new String(propertyShow.getProperty(testPartKey)。getBytes(),“gb2312”));

      arr.add(propertyShow.getProperty(testPartKey));

      array.add(arr);

      }

      }

      request.setAttribute(“box”,array);

      pcForm.reset(mapping, request);

      return mapping.findForward(“testitemone”);

      }

      }

      這個 action 并不復雜, 首先它定義了一個 properties 文件 TestItem.properties,在web服務器下的/WEB-INF/classes/resource/下面,用來記錄頁面上輸入的內(nèi)容,由于 String addValueCnWirite = new String(addValueCn.getBytes(“ISO-8859-1”)) 這個語句進行了字符轉換,所以 properties 文件中記錄的內(nèi)容大概都是這樣子的:

      test.item.cn.29=\u7F1D\u9699\u5F02\u5E38

      如果把程序改成記錄到數(shù)據(jù)庫中,也應該是這個樣子,屬于Unicode編碼吧。

      而當要把記錄的內(nèi)容輸出到客戶端時候,new String(propertyShow.getProperty(testPartKey)。getBytes(),“gb2312”)) 這個語句又把Unicode編碼轉換成了GB2312,所以要求JSP頁面charset=gb2312,這樣在windows 和 unix兩個系統(tǒng)下都可以正常顯示中文了,絕對沒有問題。

    【Struts中文問題怎么解決】相關文章:

    關于Struts中文問題的解決方法01-08

    怎么解決關鍵詞排名問題03-03

    怎么解決外網(wǎng)不能訪問IIS的問題03-30

    班組長常見問題怎么解決03-18

    怎么解決Word文檔中文字下有紅色或綠色波浪線11-29

    解決寶寶睡覺問題03-21

    基于解決問題的學習03-21

    解決電腦變慢問題的方法03-19

    如何解決頭皮問題03-18

    主站蜘蛛池模板: 国产精品成人va在线观看| 久久亚洲中文字幕精品一区四| 99热成人精品免费久久| 爽爽精品dvd蜜桃成熟时电影院| 国产精品日韩欧美在线第3页| 国产成人精品白浆久久69| 亚洲国产精品一区二区第四页| 国产精品永久免费| 久久精品国产一区| 久久国产精品成人片免费| 欧美精品三区| 真实国产乱子伦精品免费| 国产精品毛片一区二区三区| 亚洲精品成人网站在线观看| 久久精品国产WWW456C0M| 91久久精品电影| 精品国产麻豆免费人成网站| 国产久热精品无码激情| 久久久久久久久无码精品亚洲日韩| 久久精品女人天堂AV麻| 99久久99久久精品国产| 国内精品一级毛片免费看| 久久99国产精品尤物| 亚洲一区二区精品视频| 久久综合精品国产一区二区三区| jizz国产精品| 国产成人精品久久亚洲高清不卡 | 国产精品一级片| 国产精品久久久福利| 国产精品福利在线播放| 国产精品拍天天在线| 国产精品三级在线观看无码 | 久久精品国产精品青草app| 国精品午夜福利视频不卡麻豆| 精品国产一区二区三区色欲| 久久亚洲精品中文字幕| 精品一区二区三区在线成人| 国产欧美精品一区二区三区| 国产精品多人p群无码| 999国内精品永久免费视频| 成人国产精品一区二区网站|