package com.linying.util;

          import javax.servlet.http.HttpServletRequest;
          /**
           * 字符轉換工具,為解決Ajax亂碼問題
           * 
          @author Ying-er
           * 
          @since 2010-5-15 下午03:37:02
           * 
          @version 1.00 Ying-er 創建 2010-5-15 下午03:37:02
           
          */
          public final class StringFormatUtil {
              
          /**
               * 工具類,禁止實例化
               
          */
              
          private StringFormatUtil() {

              }

              
          /**
               * 字符串編碼過渡
               * 
          @param paramName
               * 
          @param request
               * 
          @return
               
          */
              
          public static String getDecodeParamFromReq(String paramName,
                      HttpServletRequest request) {
                  String retval 
          = request.getParameter(paramName);
                  
                  
          if(retval==null){
                      
          return null;
                  }
                  
                  
          try {
                      
          /**
                       * 中間用ISO-8859-1過渡
                       
          */
                      
          byte[] b = retval.getBytes("8859_1");
                      
          /**
                       * 轉換成GB2312字符
                       
          */
                      retval 
          = new String(b, "GB2312");
                  } 
          catch (Exception e) {
                      e.printStackTrace();
                  }

                  
          return retval;
              }
              
              
          /**
               * 數字編碼過渡
               * 
          @param paramName
               * 
          @param request
               * 
          @return
               
          */
              
          public  static int getDecodeIntParamFromReq(String paramName,
                      HttpServletRequest request) {
                  
                  String strParam 
          = getDecodeParamFromReq(paramName,request);
                  
                  
          int intParam;
                  
          if (strParam == null) {
                      intParam 
          = 0;
                  } 
          else {
                      Integer tmp 
          = Integer.parseInt(strParam);
                      intParam 
          = tmp.intValue();
                  }
                  
                  
          return intParam;
              }
          }
          posted on 2010-05-29 10:24 Ying-er 閱讀(327) 評論(0)  編輯  收藏 所屬分類: .Net
          主站蜘蛛池模板: 沙田区| 高州市| 旬邑县| 十堰市| 合肥市| 福贡县| 蚌埠市| 铜梁县| 肥乡县| 鹰潭市| 南召县| 东城区| 兴隆县| 凤山市| 吉木萨尔县| 自贡市| 岢岚县| 喀喇沁旗| 石首市| 海安县| 晋城| 永寿县| 鹿邑县| 报价| 宝兴县| 永顺县| 进贤县| 西乡县| 张家界市| 临猗县| 普兰县| 镇江市| 平远县| 沈阳市| 柳州市| 彝良县| 万荣县| 托克托县| 盐城市| 溧水县| 治县。|