首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > J2EE开发 >

为什么不能正确解码解决思路

2012-01-06 
为什么不能正确解码%@page importjava.net.URLDecoder%%@ page languagejava importjava.util.

为什么不能正确解码
<%@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"); 

热点排行