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

高分 在线 急求 Servlet获取参数中文编码为乱码
tomact中目前编码为此处编码格式不能改变,因为整个系统都是用这种格式:
Java code

<Connector port="8080" maxThreads="150" minSpareThreads="25" maxSpareThreads="75"
               enableLookups="false" redirectPort="8443" acceptCount="100"
               debug="0" connectionTimeout="20000" 
               URIEncoding="UTF-8"
               disableUploadTimeout="true" />


传参数页面:
HTML code

<%@ page language="java"   import="java.util.*"  pageEncoding="UTF-8"%>
<%@page import="com.zzyy.web.util.RequestHelper"%>
<%@page import="com.zzyy.knowledge.*"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
// 获取目标视频文件名称
String seqid = RequestHelper.getNotNullString(request , "seqId");
//获取附件类型
KnowledgeShowDao temp = new KnowledgeShowDao();
String medianame = temp.att_MediaName(seqid);
String swfname="D:/UP/attachment/swf/"+medianame+".swf";
System.out.println("swfname值为:xxxxxxxxxssssssssssssxxxxxxx"+swfname);

%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>文件展示</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">
 </head> 
 
  <body >
  <embed  id="embedWelcom"
            pluginspage="http://www.macromedia.com/go/getflashplayer"  
            menu="true" loop="true" play="true"
            type="application/x-shockwave-flash" style="z-index: -1;"
            wmode="transparent" src="servlet/FileStreamReader?name=<%=swfname%>"
            width="800px" height="650px"
            align="middle">
    </embed>
      
  </body>
</html>



servlet页面接受代码为:
Java code

public void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {

            System.out.println("进入获取数据流页面" );
         
            
            request.setCharacterEncoding("UTF-8"); 
            response.setContentType("text/html; charset=UTF-8");//下面已经有了类型
            String str_name = request.getParameter("name"); //获取存放地址名
            
            System.out.println("进入获取数据流页面last" +str_name);
            FileInputStream fis = new FileInputStream(str_name);
            int i=fis.available(); //得到文件大小   
            byte data[]=new byte[i];   
            fis.read(data);  //读数据   
            //读取图片的时候用下面
            //response.setContentType("image/jpeg"); 
            response.setContentType("swf"); 
            OutputStream toClient=response.getOutputStream(); //得到向客户端输出二进制数据的对象   
            toClient.write(data);  //输出数据   
              
            toClient.flush();  
            toClient.close();   
            fis.close();   
            //return null;  
    }


这个页面获取到的为乱码,各位大侠有没有解决办法??