日期:2014-05-20  浏览次数:20669 次

为什么不能正确解码
<%@page import="java.net.URLDecoder"%>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
  <base href="<%=basePath%>">
   
  <title>My JSP 'simple.jsp' starting page</title>
   
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">  
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->

  </head>
  
  <body>
<%=request.getParameter("name")%>
<%String rawstr=request.getQueryString();
String str=URLDecoder.decode(rawstr,"UTF-8");
out.println(str);

%><br/>


  </body>
</html>

输入http://localhost:8080/newPro/simple.jsp?name=李刚
应该能显示name=李刚,可是却显示name=XXX(乱码)

------解决方案--------------------
这个是肯定的

应该先编码然后解码

直接地址栏传肯定是乱码的

百度一下url编码和解码

祝楼主好运
------解决方案--------------------
Java code
String name = new String(request.getParameter("name").getBytes("ISO-8859-1"), "UTF-8");