两个简单的测试页面,第一个页面testpro.jsp代码
<%@ page language="java" contentType="text/html; charset=utf-8" import="java.sql.*,Configure.*,DB.*" pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%request.setCharacterEncoding("utf-8");
   response.setCharacterEncoding("utf-8");
String str_4="刘若英-一切.mp3";
%>
<html>
<head>
<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">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script language="javascript">
function openScript(url,name,width,height)
{
var left =  (screen.width-width)/2; 
var  top =  (screen.height-height)/2; 
var newWin =  window.open(url,name, "left= " +left+ ",top= "+top+ ",width= "+width+ ",height= "+height); 
newWin.focus(); 
return   newWin;
}
</script>
</head>
<body>
<form id="form1" name="form1" method="post" action="media.jsp"  >
 <input type="text" size="50" align="middle" id="SearchCondition" name="searchcondition" value="" />
 <input type="submit"  height="100" size="60" name="Submit"  style="font-size:   18px;" value="搜索"  />
<a href="#" onclick="openScript('media.jsp?AudioPath=<%=str_4%>','pur',400,300)">下载</a>
</form>
</body>
</html>
点击下载之后会弹出来接收页面test.jsp
<%@ page contentType="text/html; charset=utf-8" language="java" import="java.util.*,Configure.*"  pageEncoding="utf-8" %>
<%request.setCharacterEncoding("utf-8");
   response.setCharacterEncoding("utf-8");
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
//String imagepath1=(String)session.getAttribute("audiopath");
String imagepath=request.getParameter("AudioPath"); 
out.println(imagepath);
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>  
<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">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>  
 <body bgcolor="white"> 
  </body>
</html>
但是显示的结果为 刘若�?一�?mp3 一半为中文一半为乱码,该怎么解决,搞这乱码都两天了头都大了还没解决,大家可以测试一下,帮帮忙,重谢啊

解决方案 »

  1.   

    今天人少,URL的GET传递需要编码的。
      

  2.   

    <a href="#" onclick="openScript('media.jsp?AudioPath= <%=str_4%>','pur',400,300)">下载 </a> 
    改成:
    <a href="#" onclick="openScript('media.jsp?AudioPath='+encodeURIComponent('<%=str_4%>'),'pur',400,300)">下载 </a> 
      

  3.   

    我在server.xml中也添加了URIEncoding="utf-8",之前也用过过滤器之类的,貌似都不管用楼上的两位说的中文需要编码具体指的是怎么做法
      

  4.   

    谢谢jinxfei这位哥们啊,按照你的方法的确可以,分就给你了,不过上面的两位哥们也谢谢你们的关注