Paip. Troubleshoot problems with Chinese URL paths picture files cannot be displayed

Source: Internet
Author: User
Paip. Troubleshoot problems with Chinese URL paths picture files cannot be displayed

#现状: Chinese URL path picture file cannot be displayed



#原因解析
View tired-hung send D URL,,, Russia is using FF. It converts the URL into a http://localhost/img/QQ%E6%88%AA%E5%9B%BE20140401175433.jpg and sends it out. 3% characters per kanji, so, indicates that the URL is UTF8 encoded:
The server side uses D RESIN4, which is estimated not to use UTF decodes.

#解决方式
1. Change resin4 cfg, set UTF8 to URL parameter resolution .... SE, set the LEI to be ineffective ... Had to solve their own le.
2.urlrewrtite>>servlet, self-parsing URL parameters, output picture stream ...
First use JSP output picture stream, online said is ok Lan SE, walk ten not, teeth don't know why ... As basic as the output of a servlet salam ...


Author Old Wow's paw Attilax Ayron, email:1466519819@qq.com
Source: Http://blog.csdn.net/attilax

##/imserver/webroot/web-inf/urlrewrite.xml
<rule>

&LT;FROM&GT;/.*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 parameters, 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 the way to find DAO online ... Not effective ...

The configuration of the 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>

This is resin doc inside I was in web-app-default with the encoding configuration
<web-app-default>
<character-encoding>UTF-8</character-encoding>

</web-app-default>

Hope to help you with your project.

Then in the resin to modify the configuration file to set the encoding format, the method is as follows:

Open Resin-4.0.22\conf\resin.xml File

Find <web-app-default> tags, add <character-encoding>UTF-8</character-encoding>




, but when the picture is displayed in the JSP view, an exception is thrown Getoutputstream () has already been called for this response, because the request's output stream has been opened by the servlet by default , we all know that the JSP will eventually be converted into a servlet, and the output stream of the servlet is open, cannot be closed (I tested), so using JSP to open the output stream is not feasible.

So, helpless, we can only use the original servlet to achieve this function, you can directly through the servlet output stream to display the picture, no need to open the output stream


#jsp serrvelt Output comparison picture
Accept-ranges bytes
Cache-control max-age=86400
Content-length 25027
Content-type Image/jpeg
Date Thu, APR 03:22:13 GMT
Etag ""
Last-modified Wed, APR 03:31:53 GMT
Server microsoft-iis/6.0
x-powered-by ASP.
X-ua-compatible Ie=emulateie7


#my
Content-type Image/jpeg; CHARSET=GBK Jeig BSI Juyaowenti.
Date Thu, APR 03:04:12 GMT
Server resin/4.0.22
Transfer-encoding chunked

Content-length 8802
Content-type Image/jpeg; Charset=gbk
Date Thu, APR 03:07:16 GMT
Server resin/4.0.22


Err

Cache-control No-cache
Content-type Image/jpeg; Charset=gbk
Date Thu, APR 03:57:47 GMT
Expires Thu, 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, APR 03:58:49 GMT
Expires Thu, Jan 1970 00:00:00 GMT
Server resin/4.0.22
Transfer-encoding chunked, chunked

Reference:
RESIN4 Chinese Problem Solving-newflypig's column-Blog channel-csdn.net
How tomcat and resin server is set to UTF8 encoding-thought is more important than knowledge growth is more important than success-Blogjava

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.