void

          Strus2 + Freemarker + Sitemesh 亂碼解決方案


          Struts2


          1.src目錄添加文件struts.properties
          <!-- 該屬性設(shè)置Struts 2是否支持動(dòng)態(tài)方法調(diào)用,該屬性的默認(rèn)值是true。如果需要關(guān)閉動(dòng)態(tài)方法調(diào)用,則可設(shè)置該屬性為false。 -->
          struts.enable.DynamicMethodInvocation
          =true

          <!-- 該屬性指定視圖標(biāo)簽?zāi)J(rèn)的視圖主題,該屬性的默認(rèn)值是xhtml。 -->
          struts.ui.theme
          =simple

          <!-- 是否struts過(guò)濾器中提供的靜態(tài)內(nèi)容應(yīng)該被瀏覽器緩存在頭部屬性中 -->
          struts.serve.static.browserCache
          =false

          <!-- 在url中產(chǎn)生 默認(rèn)的includeParams -->
          struts.url.includeParams
          =none



          <!-- 當(dāng)struts配置文件修改后,系統(tǒng)是否重新加載配文件,默認(rèn)是false -->
          struts.configuration.xml.reload
          =true

          <!-- 開(kāi)發(fā)模式下使用,這樣可以打印出更詳細(xì)的錯(cuò)誤信息 -->   
          struts.devMode
          =true

          <!-- 修改資源文件后自動(dòng)裝載 -->
          struts.i18n.reload
          =true

          <!-- 該屬性指定XSLT Result是否使用樣式表緩存。當(dāng)應(yīng)用處于開(kāi)發(fā)階段時(shí),該屬性通常被設(shè)置為true;當(dāng)應(yīng)用處于產(chǎn)品使用階段時(shí),該屬性通常被設(shè)置為false。 -->
          struts.xslt.nocache
          =true

          <!-- action擴(kuò)展名 -->
          struts.action.extension
          =jhtml

          <!-- 默認(rèn)的國(guó)際化地區(qū)信息 -->
          struts.locale
          =zh_CN

          <!-- 國(guó)際化信息內(nèi)碼 -->
          struts.i18n.encoding
          =UTF-8




          Freemarker


          1.設(shè)置
          <result name="error" type="freemarker">
              
          <param name="location">/WEB-INF/pages/console/AccountEdit.ftl</param>
              
          <param name="contentType">text/html;charset=GBK</param>
          </result>

          2.或者在src目錄添加文件freemarker.properties
          locale=zh_CN
          default_encoding
          =UTF-8
          number_format
          =#
          date_format
          =yyyy-MM-dd
          time_format
          =HH:mm:Ss
          datetime_format
          =yyyy-MM-dd HH\:mm\:Ss





          Sitemesh


          sitemesh在處理編碼時(shí)會(huì)使用系統(tǒng)的編碼,com.opensymphony.module.sitemesh.filter.TextEncoder文件
          private static final String DEFAULT_ENCODING = System.getProperty("file.encoding");
              
          private static final boolean JDK14 =
                      System.getProperty(
          "java.version").startsWith("1.4")
                      
          || System.getProperty("java.version").startsWith("1.5");

              
          public char[] encode(byte[] data, String encoding) throws IOException {
                  
          if (encoding == null) {
                      encoding 
          = DEFAULT_ENCODING;
                  }
                  
          //encoding = "UTF-8";
                  if (JDK14) {
                      
          return get14Buffer(data, encoding);
                  } 
          else {
                      
          return get13Buffer(data, encoding);
                  }
              }

          所以需要在sitemesh啟動(dòng)前設(shè)置環(huán)境
          System.setProperty("file.encoding","UTF-8")





          Jsp


          <head>
          <%@ page contentType
          ="text/html; charset=utf-8" language="java"%>
          <%@ taglib uri
          ="http://www.opensymphony.com/sitemesh/decorator" prefix="decorator"%>
          </head>



          posted on 2011-06-07 12:40 void 閱讀(662) 評(píng)論(0)  編輯  收藏 所屬分類: Struts2

          主站蜘蛛池模板: 西盟| 彩票| 嘉黎县| 长白| 丹东市| 宽甸| 保康县| 伊宁市| 千阳县| 石首市| 射洪县| 民勤县| 扎囊县| 阿克苏市| 普兰县| 新邵县| 芜湖县| 合水县| 临湘市| 富裕县| 栾城县| 永靖县| 缙云县| 曲阳县| 札达县| 深州市| 会宁县| 衡阳市| 通化县| 仁寿县| 密云县| 获嘉县| 和政县| 石家庄市| 米易县| 大港区| 且末县| 小金县| 德化县| 永春县| 涞水县|