• <sub id="h4knl"><ol id="h4knl"></ol></sub>
    <sup id="h4knl"></sup>
      <sub id="h4knl"></sub>

      <sub id="h4knl"><ol id="h4knl"><em id="h4knl"></em></ol></sub><s id="h4knl"></s>
      1. <strong id="h4knl"></strong>

      2. Struts中文問(wèn)題怎么解決

        時(shí)間:2024-09-09 12:07:14 SUN認(rèn)證 我要投稿
        • 相關(guān)推薦

        Struts中文問(wèn)題怎么解決

          碰到struts中文問(wèn)題時(shí),JSP頁(yè)面上仍然顯示的是亂碼,下面方法在windows的weblogic8下,和unix的weblogic8下均正確顯示漢字。一起來(lái)看看吧!

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

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

          TestItem English :

          TestItem Chinese :

          注意,頁(yè)面的字符集一定要定義成gb2312,否則顯示不了正確的漢字了,代碼上半部的logic:iterate 標(biāo)簽是 action 處理完畢后,返回給頁(yè)面顯示的。至于form提交的部分,由struts機(jī)制去做了,我只把 testitem_config 這個(gè) 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”);

          }

          }

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

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

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

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

        【Struts中文問(wèn)題怎么解決】相關(guān)文章:

        關(guān)于Struts中文問(wèn)題的解決方法01-08

        怎么解決關(guān)鍵詞排名問(wèn)題03-03

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

        班組長(zhǎng)常見(jiàn)問(wèn)題怎么解決03-18

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

        解決寶寶睡覺(jué)問(wèn)題03-21

        基于解決問(wèn)題的學(xué)習(xí)03-21

        解決電腦變慢問(wèn)題的方法03-19

        如何解決頭皮問(wèn)題03-18

        国产高潮无套免费视频_久久九九兔免费精品6_99精品热6080YY久久_国产91久久久久久无码
      3. <sub id="h4knl"><ol id="h4knl"></ol></sub>
        <sup id="h4knl"></sup>
          <sub id="h4knl"></sub>

          <sub id="h4knl"><ol id="h4knl"><em id="h4knl"></em></ol></sub><s id="h4knl"></s>
          1. <strong id="h4knl"></strong>

          2. 中天堂国产日韩欧美 | 最新日本一区二区三区视频 | 亚洲中文在线播放 | 亚洲日本中文一区二区 | 亚洲性爱免费在线视频播放 | 日本真人作爱视频免费大全 |