JavaScript passes Chinese parameters to JSP pages via URL leading to garbled solution _jsp programming

Source: Internet
Author: User
Tags tomcat
2013-1-16 10:35:49 org.apache.tomcat.util.http.Parameters ProcessParameters
Warning: Parameters:character decoding failed. Parameter ' id ' with value '%u8ba2%u5355 ' has been ignored. The "name" and "value" quoted here is corrupted due to the failed decoding. Use debug level logging to the original, non-corrupted values.
Enter Servlet Get Method ...
Ok:
2013-1-16 10:35:49 Org.apache.catalina.core.StandardWrapperValve Invoke
Serious: 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)

Solving Method: In the transfer of parameters before the Chinese parameters are encoded two times, JSP page to obtain parameters for the Chinese parameters of a decoding, Chinese parameters will not become garbled!

Reference Examples
Copy Code code as follows:

<%@ 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")/Direct access to Chinese parameters
}
try{
if (Request.getparameter ("param1")!=null) {
Str1=urldecoder.decode (Request.getparameter ("param1"), "utf-8")//decoding of Chinese parameters
}
}catch (Exception e) {
E.printstacktrace ();
}
%>
<! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" >
<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 ">
<script type= "Text/javascript" >
var str= "Hello";
function Test0 () {
window.location= "test.jsp?param0=" +str;//directly transfer Chinese parameters
}
function Test1 () {
window.location= "test.jsp?param1=" +encodeuri (encodeURI (str))//two-layer encoding of Chinese parameters before transmission
}
</script>
<body>
<input VALUE=&LT;%=STR0%>>
<input type= "button" value= "garbled" onclick= "test0 ()" ><br>
<input VALUE=&LT;%=STR1%>>
<input type= "button" value= "normal" onclick= "test1 ()" >
</body>
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.