(1)jsp显示中文文件名的图片
方法一、将Tomcat中的server.xml文件中改为:
复制代码 代码如下:
<Connector port="8080" maxHttpHeaderSize="8192"
maxThreads="150" minSpareThreads="25" maxSpareThreads="75"
enableLookups="false" redirectPort="8443" acceptCount="100"
connectionTimeout="20000" disableUploadTimeout="true" URIEncoding="GBK" />
复制代码 代码如下:
<%@ page import="java.net.URLEncoder" %>
<img src="...../.../URLEncoder.encode("图片名.jpg","GBK")"/>
复制代码 代码如下:
<Connector port="8080" protocol="HTTP/1.1"
maxThreads="150" connectionTimeout="20000"
redirectPort="8443" URIEncoding="UTF-8"/>
复制代码 代码如下:
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html; charset=UTF-8");
response.setContentType("image/jpeg"); //设置图片格式格式,这里可以忽略
FileInputStream fis = new FileInputStream("D:/ftp/xxx.jpg");
OutputStream os = response.getOutputStream();
try {
int count = 0;
byte[] buffer = new byte[1024*1024];
while ( (count = fis.read(buffer)) != -1 )
os.write(buffer, 0, count);
} catch (IOException e){
e.printStackTrace();
}finally {
if(os!=null)
os.close();
if(fis != null)
fis.close();
}
}
新闻热点
疑难解答