windows下tomcat8上传临时素材时中文文件名乱码
使用HttpUrlConnection上传文件,tomcat已在server.xml设置编码为UTF-8 部分请求代码如下 这种情况下,临时附件的中文文件名还是出现了乱码,看以前的回复都是设置环境,请问该如何设置,或是需要添加什么请求头吗? URL url = new URL(uploadUrl);
connection = (HttpURLConnection) url.openConnection();
connection.setDoInput(true);
connection.setDoOutput(true);
connection.setUseCaches(false);
connection.setRequestMethod("POST");
connection.setConnectTimeout(UPLOAD_TIME_OUT);
connection.setReadTimeout(UPLOAD_TIME_OUT);
connection.setRequestProperty("Charset", "UTF-8");
connection.setRequestProperty("connection", "keep-alive");
connection.setRequestProperty("Content-Type", "multipart/form-data" + ";boundary=" + boundary);
connection.setRequestProperty("Content-Length", String.valueOf(fileSize));
dos = new DataOutputStream(connection.getOutputStream());
StringBuilder sb = new StringBuilder();
sb.append(PREFIX);
sb.append(boundary);
sb.append(LINE_END);
String s = "Content-Disposition: form-data; name=\"media\"; filename=\"" + fileName + "\""
+ LINE_END;
sb.append(s);
sb.append("Content-Type: application/octet-stream; charset=" + CHARSET_DEFAULT + LINE_END);
sb.append(LINE_END);
dos.write(sb.toString().getBytes());
byte[] bytes = new byte[8 * 1024];
int len = 0;
while ((len = is.read(bytes)) != -1) {
dos.write(bytes, 0, len);
}
dos.write(LINE_END.getBytes());
byte[] end_data = (PREFIX + boundary + PREFIX + LINE_END).getBytes();
dos.write(end_data);
dos.flush();