|
警告: Parameters: Character decoding failed. Parameter 'id' with value '%u8BA2%u5355' has been ignored. Note that the name and value quoted here may corrupted due to the failed decoding. Use debug level logging to see the original, non-corrupted values.
Enter Servlet Get Method..
OK:
2013-1-16 10:35:49 org.apache.catalina.core.StandardWrapperValve invoke
嚴(yán)重: Servlet.service() for servlet suggest threw exception
Java.lang.NullPointerException
at com.ont.demo.suggest.doGet(suggest.Java:25)
at Javax.servlet.http.HttpServlet.service(HttpServlet.Java:617)
at Javax.servlet.http.HttpServlet.service(HttpServlet.Java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.Java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.Java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.Java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.Java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.Java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.Java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.Java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.Java:298)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.Java:852)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.Java:588)
at org.apache.tomcat.util.NET.JIoEndpoint$Worker.run(JIoEndpoint.Java:489)
at Java.lang.Thread.run(Thread.Java:619)
解決方法:在傳遞參數(shù)前將中文參數(shù)進(jìn)行兩次編碼,jsp頁(yè)面獲取參數(shù)后對(duì)中文參數(shù)進(jìn)行一次解碼,中文參數(shù)就不會(huì)變?yōu)閬y碼了!
參考例子:
復(fù)制代碼 代碼如下:
<%@ 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");//直接獲取中文參數(shù)
}
try{
if(request.getParameter("param1")!=null){
str1=URLDecoder.decode(request.getParameter("param1"),"utf-8");//對(duì)中文參數(shù)進(jìn)行解碼
}
}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;//直接傳遞中文參數(shù)
}
function test1(){
window.location="Test.jsp?param1="+encodeURI(encodeURI(str));//對(duì)中文參數(shù)進(jìn)行雙層編碼后再傳遞
}
</script>
</head>
<body>
<input value=<%=str0 %>>
<input type="button" value="亂碼" onclick="test0()"><br>
<input value=<%=str1 %>>
<input type="button" value="正常" onclick="test1()">
</body>
</html>
jsp技術(shù):javascript通過url向jsp頁(yè)面?zhèn)鬟f中文參數(shù)導(dǎo)致亂碼解決方案,轉(zhuǎn)載需保留來源!
鄭重聲明:本文版權(quán)歸原作者所有,轉(zhuǎn)載文章僅為傳播更多信息之目的,如作者信息標(biāo)記有誤,請(qǐng)第一時(shí)間聯(lián)系我們修改或刪除,多謝。