老妖的博客
现实的中没有几个人能够真为对方去死,甚至山盟海誓很快就会在金钱面前变的微不足道,这才是生活。没有永远的爱,除了你的父母对你,当然也就没有永远的恨,更没有永远的痛,时间是最好的治疗大师,它会很快抚平你心灵上累累的伤痕。很多年以后你想起来时,那些在你生命中汹涌来往的人群至多是个模糊的影子或者毫无意义的名字
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 老妖 阅读(3873) 评论(0)  编辑  收藏 所属分类: java心得spring

只有注册用户登录后才能发表评论。


网站导航:
 

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

常用链接

随笔分类(48)

随笔档案(104)

好友链接

我的豆瓣

积分与排名

  • 积分 - 218718
  • 排名 - 256

最新评论

阅读排行榜