標籤:baidu   解決辦法   web app   亂碼問題   取數   資料庫   get   tchar   pst   
有如下幾種解決辦法:
1、保證項目的字元編碼和每一個jsp頁面的字元編碼一致,如果不一致可能導致中文亂碼問題<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
2、編寫Filter過濾器,在過濾器的過濾方法doFilter中寫
        request.setCharacterEncoding("UTF-8");
        response.setContentType("text/html;charset=UTF-8");
       在web.xml中配置如下資訊,過濾全部請求
        <filter>
          <filter-name>characterFilter</filter-name>
          <filter-class>自訂Filter類的全限定類名</filter-class>
      </filter>
      <filter-mapping>
           <filter-name>characterFilter</filter-name>
           <url-pattern>/*</url-pattern>
    </filter-mapping>
3、在web.xml中加入jsp配置資訊
<jsp-config>
          <jsp-property-group> 
            <description> For config the web application </description> 
            <display-name>JSPConfiguration</display-name> 
            <url-pattern>*.jsp</url-pattern> 
            <el-ignored>false</el-ignored>             
            <page-encoding>UTF-8</page-encoding>           
        </jsp-property-group>
</jsp-config>
在jsp中
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
以上三種方式均可以實現,建議選擇第二種方式,針對任意請求,jsp和servlet都可以解決中文問題
java 讀取資料庫中文資訊,為何在jsp頁面中出現亂碼