我要实现如下效果:
1.实现在一个JSP页面中可以显示图片的效果.
2.这个图片的文件名是中文的而且必须是中文的(这是人家客户要求的以"机构名+用户姓名+ID").
3.我在JSP页面中可以获取这个路径.如:http://localhost:8080/snhy/uploads/aaa.jpg或http://localhost:8080/snhy/uploads/张三aaa.jpg
4.显示英文和数字命名的图片都可以正常显示出来,如果要显示含有中文的图片就出问题了,显示不出来.我的解决办法:
1.String tempphotoname=new String(photoname.getBytes("ISO-8859-1"), "UTF-8");//对其中文文件名转码但还是不显示.
2.使用java.java.net.URLEncoder.encode(photoname,"UTF-8");//也是不行,3.也问了好多朋友,也从网上搜了N次最未找到答案,在此希望大家可以帮我想想办法(可不要说命名不用中文这个我也知道,就是客户比较挑剔必须是中文命名且读取的是中文命名的方法).首先谢谢大家来关注了,等待中…………………………

解决方案 »

  1.   

    http://topic.csdn.net/u/20080612/20/d31529ab-c98e-4893-931b-68cc0e9f5b87.html
    好像和你的一样
      

  2.   

    JSP 页编码改为 UTF-8 或 GBK。
    <%@ page contentType="text/html; charset=UTF-8" %>
      

  3.   

    java.java.net.URLEncoder.encode(photoname,"UTF-8");
    是photoname = java.net.URLEncoder.encode(photoname,"UTF-8");
      

  4.   

    photoname = java.net.URLEncoder.encode(photoname,"UTF-8");
      

  5.   


      <Connector port="8080" 
       maxThreads="150" minSpareThreads="25" maxSpareThreads="75" 
       enableLookups="false" redirectPort="8443" acceptCount="100" 
       debug="0" connectionTimeout="20000" 
       disableUploadTimeout="true"  useBodyEncodingForURI="true" URIEncoding="UTF-8"/> 中加入useBodyEncodingForURI="true" URIEncoding="UTF-8"就可以了. 
      

  6.   


    不好意思.我用的是:
    java.net.URLEncoder.encode(photoname,"UTF-8");//也是不行, 
    这一行没有错.
    谢谢大家了.
    我已经解决了.非常感谢大家的关注.希望大家能给我解决以下这个问题.这是个用下载从"url"传过来值的处理代码,url得到的是一个文件夹及下面的文件名如:"/uploads/中国dfs.pdf";<%@ page contentType="text/html; charset=utf-8"%>
    <%@ page import="java.io.*" %>
    <%
    response.setContentType("text/html;charset=utf-8");
    request.setCharacterEncoding("utf-8");
    response.setCharacterEncoding("utf-8");
        String url = request.getParameter("url");
        int a=url.lastIndexOf("/");
    String filename=new String(url.substring(a+1).getBytes("ISO-8859-1"), "UTF-8");
    String tttt=request.getSession().getServletContext().getRealPath("/");
    System.out.println(tttt+filename+"                      tttt");
        String urlz = "D:/apache-tomcat-5.5.25/webapps/SNHY"+url;
       System.out.println(urlz+"======================");
        File file = new File(urlz);
        System.out.println(urlz+"++++++++++++++++++++++++++++++");
       // response.setHeader("Content-Disposition", "attachment; filename=download.jpg" );
       response.setHeader("Content-Disposition", "attachment; filename=" +filename);
    //filename为中文的文件名,我想下载的时候默认名是原来的文件名所以就这样写了
       System.out.println("|||||||||||||||"+urlz);
        //以流的形式写出文件
       try{
     FileInputStream bis = new FileInputStream(file);
        OutputStream bos = response.getOutputStream();
        byte[] buff = new byte[1024];
        int readCount = 0;
        readCount = bis.read(buff);
        while (readCount != -1) {
            bos.write(buff, 0, readCount);
            readCount = bis.read(buff);
        }
        if (bis != null) {
            bis.close();
        }
        if (bos != null) {
           bos.close();
        }
        //下载完毕,给浏览器发给完毕的头
        response.setStatus(HttpServletResponse.SC_OK);
        response.flushBuffer();
        //解决getOutputStream() has already been called for this response 错误
        out.clear();
       out=pageContext.pushBody();
       }catch(Exception e){
       }%>我会加分给解答者的.
      

  7.   

    楼主,解决了要把你就解决的方法贴出来啊,浪费这么多人给你支招了。
    一般我们项目都是这样解决:http://apps.hi.baidu.com/share/detail/21624627