paip.解决中文url路径的问题图片文件不能显示



#现状..中文url路径 图片文件不能显示

<img src="img/QQ截图20140401175433.jpg" width="168" height="142" id="imgx" />





#原因解析

查看累挂发送d url,,,俄使用的是ff..它把url转换成个 http://localhost/img/QQ%E6%88%AA%E5%9B%BE20140401175433.jpg 发送出去..每汉字3个%字符,所以,表明是utf8编码的url..

服务端使用d resin4,估计不使用utf decodes..



#解决方式

1.更改resin4 cfg ,设置utf8为url参数解析....se,设置lei 不起效果...只好自己解决le ..

2.urlrewrtite>>servlet ,自己解析url参数,输出图片流...

先是使用jsp输出图片流,网上说是ok兰se ,走十不行,牙不晓得为甚...跟个servlet输出的基本的一样兰木...





作者 老哇的爪子 Attilax 艾龙,  EMAIL:1466519819@qq.com

来源: http://blog.csdn.net/attilax



##/imServer/WebRoot/WEB-INF/urlrewrite.xml

      <rule>

       

        <from>/.*QQ(.*).jpg</from>

        <to>/visitorBuscard_list.json?data=showimg&amp;urlCnChar=$1</to>

    </rule>

##     spring mvc cfg

//todo spring mvc hot deplyoy

@RequestMapping(value = "/visitorBuscard_list" )



public void visitorBuscard_list(String data, HttpServletResponse response,HttpServletRequest request)   {

    core.log("--data:"+data);

    if(data!=null){

        if(data.equals("probelist"))

        {

            baseList(response,new TProbeCustomDAO());

        }else if(data.equals("vistInvtSet"))

        {

            new probeService().saveVistInvtSet(request);

        }

        else if(data.equals("showimg"))

        {

            imgService.outputImg(request, response);

        }

    }else

##pasrse url 参数,output pic

    public static void outputImg(HttpServletRequest req,

            HttpServletResponse response) {

        

    String uri=    req.getRequestURI();

    core.log(" --get uri:"+uri);

    core.log(" --get url:"+req.getRequestURL());

    core.log(" --getQueryString:"+req.getQueryString());

    Map m=    urlUtil.Param2Map(req);

    core.log("--o4f1");

    listUtil.print(m);

    String jpgPart=m.get("urlCnChar".toLowerCase()).toString();

    String jpgPart_real=urlUtil.decodeByUtf8(jpgPart);

    jpgPart_real=jpgPart;

    String realPath=pathx.webAppPath(req)+"/img/QQ"+jpgPart_real+".jpg";

    core.log("--realpath:"+realPath);

        response.reset();

         response.setHeader("Cache-Control", "no-cache");  

            response.setDateHeader("Expires", 0);  

         response.setContentType("image/jpeg");

    //    response.setHeader("Content-Type", "image/jpeg4");

     //    response.setHeader("Transfer-Encoding", "chunked");

             

    

        

        ServletOutputStream sout = null;

        try {

            sout = response.getOutputStream();

        } catch (Exception e1) {

            core.log(e1);

        }

        // InputStream in = rs.getBinaryStream(1);

        // byte b[] = new byte[0x7a120];

        // in.read(b);

        byte[] b = imgUtil.toByteArr(realPath);

     response.setContentLength(b.length);

        try {

            sout.write(b);

        

            sout.flush();

        

        //    response.flushBuffer();

            sout.close();

        } catch (Exception e) {

            core.log(e);

        }



    }





#resin4 网上寻找dao的方法...不起生效...



    Resin的配置。(conf/resin.conf)



    character-encoding

        Resin 1.1

    child of: resin, server, host-default, host, web-app-default, web-app

    default: The default value is ISO-8859-1.



    Specifies the default character encoding for the environment.



    <web-app id='/'>

                    <character-encoding>shift_jis</character-encoding>

                    ...

                    </web-app>



     这个是resin doc里面的我是在web-app-default里面加上了encoding的配置

    <web-app-default>

      <character-encoding>UTF-8</character-encoding>

      

    </web-app-default>



希望对你的项目有帮助。



于是在Resin中就要修改配置文件来设置编码格式,方法如下:



打开resin-4.0.22\conf\resin.xml文件



找到<web-app-default>标签,添加<character-encoding>UTF-8</character-encoding>









题,但是将图片显示在Jsp视图的时候,就会抛出一个异常getOutputStream() has already been called for this response,这是因为,request的输出流已经默认被servlet打开,大家都知道Jsp最终会被转化成servlet,而servlet的输出流已经打开,无法关闭(本人测试过),所以用Jsp来打开输出流是行不通的。



       所以,无奈之下,我们只能用原始的servlet来实现这个功能,可以直接通过servlet的输出流来显示图片,没必要再打开输出流





#jsp serrvelt 输出比较图片

Accept-Ranges    bytes

Cache-Control    max-age=86400

Content-Length    25027

Content-Type    image/jpeg

Date    Thu, 17 Apr 2014 03:22:13 GMT

Etag    ""

Last-Modified    Wed, 16 Apr 2014 03:31:53 GMT

Server    Microsoft-IIS/6.0

X-Powered-By    ASP.NET

X-UA-Compatible    IE=EmulateIE7





#my

Content-Type    image/jpeg; charset=GBK  jeig bsi juyaowenti..

Date    Thu, 17 Apr 2014 03:04:12 GMT

Server    Resin/4.0.22

Transfer-Encoding    chunked



Content-Length    8802

Content-Type    image/jpeg; charset=GBK

Date    Thu, 17 Apr 2014 03:07:16 GMT

Server    Resin/4.0.22





err



Cache-Control    no-cache

Content-Type    image/jpeg; charset=GBK

Date    Thu, 17 Apr 2014 03:57:47 GMT

Expires    Thu, 01 Jan 1970 00:00:00 GMT

Server    Resin/4.0.22

Transfer-Encoding    chunked, chunked





---corect



Cache-Control    no-cache

Content-Type    image/jpeg; charset=GBK

Date    Thu, 17 Apr 2014 03:58:49 GMT

Expires    Thu, 01 Jan 1970 00:00:00 GMT

Server    Resin/4.0.22

Transfer-Encoding    chunked, chunked



参考:

Resin4中文问题解决办法 - newflypig的专栏 - 博客频道 - CSDN.NET

tomcat and resin服务器如何设为UTF8编码 - 思想比知识更重要 成长比成功更重要 - BlogJava

paip.解决中文url路径的问题图片文件不能显示的更多相关文章

  1. 解决“用PicGo-2.3.0-beta5 + GitHub做博客图床,github仓库图片文件不显示”的问题记录(备忘)

    解决"用PicGo-2.3.0-beta5 + GitHub做博客图床,github仓库图片文件不显示"的问题记录(备忘) 历时几个小时百度,终于靠自己理解解决了GitHub仓库图 ...

  2. FileReader:读取本地图片文件并显示

    最近忙得比狗还惨,导致长时间没能更新文章,真心对不住啊.抽空整理了下关于在页面上读取和显示本地图片的实例文章,本文通过实例讲解如何使用支持FileReader浏览器的用户将能够通过一个file inp ...

  3. (已解决)Eclipsez中打不开c++文件,显示Editor could not be initialized.

    新建的游戏导入Eclipse能正常运行,配置什么的都弄好了,游戏运行无任何问题!问题是:关闭Eclipse后,重新打开,就会出现An internal error occurred during: & ...

  4. JAVA中解决Filter过滤掉css,js,图片文件等问题

    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOE ...

  5. 转:JAVA中解决Filter过滤掉css,js,图片文件等问题

    原文链接:https://www.cnblogs.com/ermeng/p/6440966.html public void doFilter(ServletRequest request, Serv ...

  6. Web---演示servlet技术(servlet生命周期),解决中文乱码问题

    本节讲解决中文乱码问题的4种方法. 还有更好的方法,也就是用过滤器,这里就不演示了,博主目前也不会~呼♪(^∇^*)~过段时间才会学. servlet生命周期演示: index.jsp: <%@ ...

  7. Eclipse+pydev解决中文显示和注释问题的方法大全

    Eclipse+pydev解决中文显示和注释问题的方法大全 Eclipse的设置 window->preferences->general->editors->textedit ...

  8. springmvc+jsp引用本地图片文件

    1.图片文件路径,注意图片文件夹和WEB-INFO文件夹同级 2.web.xml配置 <servlet-mapping> <servlet-name>default</s ...

  9. div中粘贴图片并上传服务器 div中拖拽图片文件并上传服务器

    应用简介:此文主要是描述如何在前端div中直接ctrl+v 粘贴图片,并上传到服务器,包括拖拽图片文件到div中 应用场景描述:用QQ或者其它切图软件截图,在指定的div中ctrl+v 粘贴并显示,点 ...

随机推荐

  1. java.lang.UnsupportedClassVersionError: xxx/xxxClass : Unsupported major.minor version 51.0

    完全参考自 http://www.cnblogs.com/xing901022/p/4172410.html 这种错误的全部报错信息: 1 java.lang.UnsupportedClassVers ...

  2. C#将Enum枚举映射到文本字符串

    介绍 当将以前的C代码移植到C#中时,我快发疯了,因为有很多的数组需要将常量映射到字符串.当我在寻找一个C#的方法来完成的时候,我发现了一个自定义属性和映射的方法. 如何使用代码? 对每一个enum枚 ...

  3. myBatis自动生成mapping,dao和model

    myBatis没有自动封装实体类.所以都需要自己编写,但是表数据过多时.编写难度就会增加,错误率也会增加! 所以myBatis提供mybatis-generator-core-1.3.2-bundle ...

  4. IT_sort用法实例

    form fill_it_sort.     iw_sort-spos = '1'.      iw_sort-fieldname = 'AUFNR'.      iw_sort-up = 'X'. ...

  5. python学习笔记-Day6(3)

    代码书写原则: 1)不能重复写代码 2)写的代码要经常变更 编程模式概述 面向过程:根据业务逻辑从上到下写垒代码 函数式:将某功能代码封装到函数中,日后便无需重复编写,仅调用函数即可 面向对象:对函数 ...

  6. python profile

    一.profile,cProfile 1. python -m cProfile myprogram.py python -m profile myprog.py2. 使用import profile ...

  7. Android(Xamarin)之旅(二)

    新的一年,新的开始,2016,我要做什么,大家要做什么,啦啦啦. OK,上篇已经介绍了几个简单的控件,这次,我们继续说说控件.但是可能有人认为这有什么难的,问题不在这里,而在于,如果你注意了每一个空间 ...

  8. 韩服MU

    ※◆☆★☆◆※欢迎使用!!!如有问题或新功能需求请联系作者QQ:82850696*4*您使用的测试版已到期,如需继续使用,请联系作者 QQ : 82850696*0*2015-1-7 23:59:59 ...

  9. js 获取、清空 input type="file"的值 .(转)

    上传控件基础知识说明: 上传控件(<input type="file"/>)用于在客户端浏览并上传文件,用户选取的路径可以由value属性获取,但value属性是只读的 ...

  10. hdu 1003

    Max Sum Time Limit: 1000MS   Memory Limit: 32768KB   64bit IO Format: %I64d & %I64u Submit Statu ...