老妖的博客
          現實的中沒有幾個人能夠真為對方去死,甚至山盟海誓很快就會在金錢面前變的微不足道,這才是生活。沒有永遠的愛,除了你的父母對你,當然也就沒有永遠的恨,更沒有永遠的痛,時間是最好的治療大師,它會很快撫平你心靈上累累的傷痕。很多年以后你想起來時,那些在你生命中洶涌來往的人群至多是個模糊的影子或者毫無意義的名字
          posts - 105,  comments - 171,  trackbacks - 0
          web.xml
          <?xml version="1.0" encoding="UTF-8"?>
          <!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" " http://java.sun.com/dtd/web-app_2_3.dtd ">
           
          <web-app>
           
              
          <filter>
                  
          <filter-name>sitemesh</filter-name>
                  
          <filter-class>com.opensymphony.module.sitemesh.filter.PageFilter</filter-class> 
              
          </filter>
           
              
          <filter-mapping>
                  
          <filter-name>sitemesh</filter-name>
                  
          <url-pattern>/*</url-pattern>
              
          </filter-mapping>
           
          <filter> 
            
          <filter-name>encodingFilter</filter-name>
            
          <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
            
          <init-param>
             
          <param-name>encoding</param-name> 
             
          <param-value>UTF-8</param-value>
            
          </init-param>
            
          <init-param>
             
          <param-name>forceEncoding</param-name>
             
          <param-value>true</param-value>
            
          </init-param> 
           
          </filter>
            
          <filter-mapping>
            
          <filter-name>encodingFilter</filter-name>
            
          <url-pattern>*.jsp</url-pattern>
           
          </filter-mapping>
          </web-app>
          sitemesh.xml:
          <?xml version="1.0" encoding="utf-8"?>
          <sitemesh>
              
          <property name="decorators-file" value="/WEB-INF/decorators.xml"/> 
              
          <excludes file="${decorators-file}"/> 
              
          <page-parsers>
                  
          <parser default="true" class="com.opensymphony.module.sitemesh.parser.HTMLPageParser"/>
                  
          <parser content-type="text/html" class=" com.opensymphony.module.sitemesh.parser.HTMLPageParser"/>
                  
          <parser content-type="text/html;charset=UTF-8" class="com.opensymphony.module.sitemesh.parser.HTMLPageParser"/>
              
          </page-parsers> 
           
              
          <decorator-mappers>
                  
          <mapper class="com.opensymphony.module.sitemesh.mapper.ConfigDecoratorMapper">
                      
          <param name="config" value="${decorators-file}"/> 
                  
          </mapper>
              
          </decorator-mappers>
          </sitemesh>
          decorators.xml:
          <?xml version="1.0" encoding="utf-8"?>
           
          <decorators defaultdir="/decorators">
              
          <decorator name="main" page="test.jsp">
                  
          <pattern>/*</pattern>
              
          </decorator>
           
              
          <decorator name="panel" page="panel.jsp"/>
              
          <decorator name="printable" page="printable.jsp"/>
          </decorators> 
          decorator的頁面test.jsp:
          <%@ page contentType="text/html; charset=utf-8"%>
          <%@ taglib uri=" http://www.opensymphony.com/sitemesh/decorator" prefix="decorator" %>
          <%@ taglib uri=" http://www.opensymphony.com/sitemesh/page" prefix="page" %>
          <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" " http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
          <html xmlns="http://www.w3.org/1999/xhtml ">
          <head>
          <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
          <title><decorator:title default="Mysterious page" /></title> 
          <decorator:head />
          </head>
           
          <body>
          <table width="100%" height="100%" border="0">
            
          <tr>
              
          <td width="29%"></td>
              
          <td width="71%">&nbsp;哈哈 哈哈 
               
          </td>
            
          </tr>
            
          <tr>
              
          <td><decorator:body /></td>
              
          <td>&nbsp;</td>
            
          </tr>
          </table>
          </body>
          </html> 
          被裝飾器頁面1.jsp:
          <%@ page contentType="text/html;charset=utf-8"%>
          <html>
              
          <head>
              
          <meta http-equiv="Content-Type" content="text/html;charset=utf-8">  
              
          <title>哈哈</title>
              
          </head>        
              
          <body>
                  
          <h2>哈哈</h2>
              
          </body>
          </html>
          作業環境:
          weblogic sp 5
          spring 1.2.6
          sitemesh 2.2.1
          發現有中文亂碼問題。

          在google上查找很久都沒有方法解決,后懷疑是處理編碼的org.springframework.web.filter.CharacterEncodingFilter中的代碼中只對request做了編碼處理而沒有對response做編碼處理
          自己對其做了一點小的修改紅色字部分
          protected void doFilterInternal(
                      HttpServletRequest request, HttpServletResponse response, FilterChain filterChain)
                      
          throws ServletException, IOException {
                  
          super.doFilter(request,response,filterChain);
                  
                  
          if (this.forceEncoding || request.getCharacterEncoding() == null) {
                      request.setCharacterEncoding(
          this.encoding);
                      response.setContentType(
          "text/html; charset="+this.encoding);
                  }
                  filterChain.doFilter(request, response);
              }
          解決亂碼問題
          posted on 2005-12-18 12:39 老妖 閱讀(3895) 評論(0)  編輯  收藏 所屬分類: java心得spring

          <2005年12月>
          27282930123
          45678910
          11121314151617
          18192021222324
          25262728293031
          1234567

          常用鏈接

          隨筆分類(48)

          隨筆檔案(104)

          好友鏈接

          我的豆瓣

          積分與排名

          • 積分 - 221161
          • 排名 - 257

          最新評論

          閱讀排行榜

          主站蜘蛛池模板: 睢宁县| 江津市| 万盛区| 逊克县| 若羌县| 天气| 平凉市| 元谋县| 都江堰市| 定结县| 罗江县| 资源县| 武夷山市| 方山县| 望城县| 进贤县| 斗六市| 福建省| 贵州省| 平顺县| 玉山县| 都兰县| 乐陵市| 理塘县| 台北市| 连江县| 远安县| 华坪县| 屏边| 德惠市| 兴城市| 德化县| 万载县| 庆安县| 沂源县| 海城市| 台北市| 开平市| 新巴尔虎右旗| 五大连池市| 上犹县|