没有人帮忙吗?分不够再说,帮我搞定先好吗?多谢
解决方案 »
- 请大家指导一下,看看这个是考的什么
- 如何取defaulttablemodel一行的数据
- java修改密码的问题
- java程序监视全局键盘,急,请帮忙!谢谢!
- Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");这个类在哪个.jar文件中
- ● [求助]:关于jdk的例子SwingSet
- 一个有点难度的字符串替换问题,解决或提示都给分----在线等待
- 传教士和野人问题,没学过数据结构的人也可以看,解决者另加高分
- ★jacob1、bowlder(玩石) 、iamsoloist(Soloist)、xiejiaohui来拿分啊! 谢谢!
- 收集SCJP的关于Intput/Output和Thread章节的试题及答案.
- 服务器上文件的下载???
- 关于在JAVA中使用数据连接的问题
*/
public static String getChineseFileName(Part body){
return ToolKit.toChinese(getISOFileName(body));
} /*
@从BodyPart中提取使用ISO-8859-1编吗的文件名
@因为BodyPart.getFilename()过程已经对文件名作了一次编码,有时不能直接使用
*/
public static String getISOFileName(Part body){
//设置一个标志,判断文件名从Content-Disposition中获取还是从Content-Type中获取
boolean flag=true;
if(body==null){
return null;
}
String[] cdis;
try{
cdis=body.getHeader("Content-Disposition");
}
catch(Exception e){
return null;
}
if(cdis==null){
flag=false;
}
if(!flag){
try{
cdis=body.getHeader("Content-Type");
}
catch(Exception e){
return null;
}
}
if(cdis==null){
return null;
}
if(cdis[0]==null){
return null;
}
//从Content-Disposition中获取文件名
if(flag){
int pos=cdis[0].indexOf("filename=");
if(pos<0){
return null;
}
//如果文件名带引号
if(cdis[0].charAt(cdis[0].length()-1)=='"'){
return cdis[0].substring(pos+10,cdis[0].length()-1);
}
return cdis[0].substring(pos+9,cdis[0].length());
}
else{
int pos=cdis[0].indexOf("name=");
if(pos<0){
return null;
}
//如果文件名带引号
if(cdis[0].charAt(cdis[0].length()-1)=='"'){
return cdis[0].substring(pos+6,cdis[0].length()-1);
}
return cdis[0].substring(pos+5,cdis[0].length());
}
}