GBK编码页面与UTF8编码页面集成

GBK编码JPS页面a.jsp:
<% @page contentType="text/html;charset=gbk" %>
<% @page import="java.util.*" %>
< html >
< meta  http-equiv ="Content-Type"  content ="text/html; charset=gbk" >
< body >
< form  action ="http://localhost:8080/b.jsp"  method ="post" >
 
< input    name  = "title"   value ="中文乱码测试"   />
 
< input  type ="submit" >
form >
body >
UTF8编码JSP页面b.jsp:
<% @page contentType="text/html;charset=utf-8"  %>
<% @page import="java.util.*" %>
<% @page import="org.apache.commons.io.*" %>
< html >
    
< meta  http-equiv ="Content-Type"  content ="text/html; charset=utf-8" />
<%  String title = request.getParameter("title");  %>
< body >
body >
html >
在b.jsp页面通过request获取title参数值出现中文乱码问题,如果不指定request参数的编码方式则默认
使用ISO-8859-1编码,因此为了获取正确的中文内容需要使用 request.setCharacterEncoding("GBK");
注意: 在web.xml中使用过滤器对request参数集合进行编码的问题:
     < filter >
        
< filter-name > webwork filter-name >
        
< filter-class >
            com.opensymphony.webwork.dispatcher.FilterDispatcher
        
filter-class >
    
filter >     
        
< filter-mapping >
        
< filter-name > webwork filter-name >
        
< url-pattern > *.jsp 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 >



你可能感兴趣的:(JSP&Servlet)