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


    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.22conf esin.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
  • 相关阅读:
    oracle11g expdp/impdp数据库
    SqlServer触发器
    tomcat8.5.20配置https
    oracle常用函数积累
    Eclipse 搭建tomcat+动态项目完整版
    Windows7下ftp服务器
    Orcle定时生成表数据作业
    Oracle将一列值逗号拼接wm_concat函数
    Oracle表空间 ORA-01653:
    node+mongodb+ionic+cordova
  • 原文地址:https://www.cnblogs.com/attilax/p/5964014.html
Copyright © 2020-2023  润新知