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&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路径的问题图片文件不能显示的更多相关文章
- 解决“用PicGo-2.3.0-beta5 + GitHub做博客图床,github仓库图片文件不显示”的问题记录(备忘)
解决"用PicGo-2.3.0-beta5 + GitHub做博客图床,github仓库图片文件不显示"的问题记录(备忘) 历时几个小时百度,终于靠自己理解解决了GitHub仓库图 ...
- FileReader:读取本地图片文件并显示
最近忙得比狗还惨,导致长时间没能更新文章,真心对不住啊.抽空整理了下关于在页面上读取和显示本地图片的实例文章,本文通过实例讲解如何使用支持FileReader浏览器的用户将能够通过一个file inp ...
- (已解决)Eclipsez中打不开c++文件,显示Editor could not be initialized.
新建的游戏导入Eclipse能正常运行,配置什么的都弄好了,游戏运行无任何问题!问题是:关闭Eclipse后,重新打开,就会出现An internal error occurred during: & ...
- JAVA中解决Filter过滤掉css,js,图片文件等问题
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOE ...
- 转:JAVA中解决Filter过滤掉css,js,图片文件等问题
原文链接:https://www.cnblogs.com/ermeng/p/6440966.html public void doFilter(ServletRequest request, Serv ...
- Web---演示servlet技术(servlet生命周期),解决中文乱码问题
本节讲解决中文乱码问题的4种方法. 还有更好的方法,也就是用过滤器,这里就不演示了,博主目前也不会~呼♪(^∇^*)~过段时间才会学. servlet生命周期演示: index.jsp: <%@ ...
- Eclipse+pydev解决中文显示和注释问题的方法大全
Eclipse+pydev解决中文显示和注释问题的方法大全 Eclipse的设置 window->preferences->general->editors->textedit ...
- springmvc+jsp引用本地图片文件
1.图片文件路径,注意图片文件夹和WEB-INFO文件夹同级 2.web.xml配置 <servlet-mapping> <servlet-name>default</s ...
- div中粘贴图片并上传服务器 div中拖拽图片文件并上传服务器
应用简介:此文主要是描述如何在前端div中直接ctrl+v 粘贴图片,并上传到服务器,包括拖拽图片文件到div中 应用场景描述:用QQ或者其它切图软件截图,在指定的div中ctrl+v 粘贴并显示,点 ...
随机推荐
- 把 TBytes 转换为十六进制字符串
function BytestoHexString(ABytes: TBytes; len: Integer): AnsiString; begin SetLength(Result, len*) ...
- GNUPLOT 画多组柱状图 以及 折线图 以及各种问题的解决方案
在Windows下使用客户端,直接可以打开.plt文件的gnuplot格式的文件,open->xx.plt 在Linux下使用shell 运行gnuplot脚本, 结果一闪而过.解决办法是在 程 ...
- RabbitMQ 学习记录
rabbit mq知识点:1.消费时可以通过acknowledge设定消费是否成功,消费不成功时在server端requeue2.需要注意两个持久化:queue持久化和消息持久化(通过代码设定,默认即 ...
- Android自动化预备(下)
上次说道:要具备的一些知识,还有多ADB得理解 本次继续ADB理解: AndroidDebugBridge debugBridge =AndroidDebugBridge.createBridge(& ...
- 遇到的check the manual that corresponds to your MySQL server version for the right syntax错误
遇到的check the manual that corresponds to your MySQL server version for the right syntax错误. 结果发现是SQL关键 ...
- 线程学习笔记(EventWaitHandler)AutoResetEvent的使用
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...
- 如何在命令行里运行python脚本
python是一款应用非常广泛的脚本程序语言,谷歌公司的网页就是用python编写.python在生物信息.统计.网页制作.计算等多个领域都体现出了强大的功能.python和其他脚本语言如java.R ...
- JavaScript-hash数组for in 函数
什么是数组:内存中,连续存储多个数据的存储空间,再起一个名字为什么; 为什么:现实存储多个相关数据,都是集中存储,共同一个名字 程序=数据结构+算法 好的数据结构可以极大的提高程序的执行效率 何时使用 ...
- Linux下的网络远程安装
Linux下的网络远程安装 1.用RHEL6.5光盘安装第一台服务器 2.在第一台服务器上配置YUM服务器 先创建一个挂载 #mount #umount /dev/cdrom #mkdir /mnt/ ...
- Linux和Windows下查看、设置环境变量的比较
[一]查看环境变量: 1.windows 查看所有的变量:set 范例:>set 查看某个变量的值:set 环境变量名 范例: >set JAVA_HOME ...