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 閱讀(666) 評(píng)論(0)  編輯  收藏 所屬分類: Struts2

          主站蜘蛛池模板: 岳池县| 策勒县| 长海县| 三亚市| 海兴县| 旅游| 铅山县| 曲沃县| 莱西市| 三台县| 突泉县| 宜阳县| 天峨县| 周至县| 漾濞| 敖汉旗| 承德县| 陈巴尔虎旗| 西和县| 理塘县| 连州市| 襄樊市| 阜南县| 宝山区| 介休市| 河池市| 玉田县| 越西县| 邛崃市| 望奎县| 宜川县| 定南县| 永登县| 莱西市| 会东县| 和平区| 晋城| 巴林右旗| 定远县| 平潭县| 应城市|