1. 程式人生 > >快逸報表傳遞中文引數亂碼解決

快逸報表傳遞中文引數亂碼解決

解決方法:在傳遞引數前將中文引數進行兩次編碼,jsp頁面獲取引數後對中文引數進行一次解碼,中文引數就不會變為亂碼了!

參考例子:

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ page import="java.net.*" %>
<%
String str0="";
String str1="";
      if(request.getParameter("param0")!=null){
        str0=request.getParameter("param0");//直接獲取中文引數
       }
try{
     if(request.getParameter("param1")!=null){
       str1=URLDecoder.decode(

request.getParameter("param1"),"utf-8");//對中文引數進行解碼
      }
}catch(Exception e){
     e.printStackTrace();
  }
%> 
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script type="text/javascript">
var str="你好";
function test0(){
window.location="Test.jsp?param0="+str;//直接傳遞中文引數
}
function test1(){
window.location="Test.jsp?param1="+encodeURI(
encodeURI(str));//對中文引數進行雙層編碼後再傳遞
}
</script>
</head>
<body>
<input value=<%=str0 %>>
<input type="button" value="亂碼" onclick="test0()"><br>
<input value=<%=str1 %>>
<input type="button" value="正常" onclick="test1()">
</body>
</html>

加密兩次,解密兩次