试试:
part.getFileName()改成new String(part.getFileName(),"ISO-8859-1")
part.getFileName()改成new String(part.getFileName(),"ISO-8859-1")
解决方案 »
- jsp向sql2000添加数据为null
- Ext js tablpanel 中数据保存的时出现的问题?
- 关于struts2(看了一个小时没看出啥问题)
- 在windows下写一个java程序用来时刻监控另一个java程序
- 各位大大,帮忙看下这个小程序怎么写!小弟无限感激
- 有状态SESSION BEAN 和无状态SESSION BEAN 的区别和联系,大家怎么理解的.
- 请教MIS系统的开发架构
- 到底怎样才能学好java?
- j2ee 工程之间实体bean的操作
- 再次遇到问题,望大虾指教。有关XML解析的。等呀等呀
- WebServer怎么获取客户端的网卡号?
- 求助!!有用rose作过基于j2EE架构的详细设计的朋友吗?
part.getFileName()改成new String(part.getFileName().getBytes(),"ISO-8859-1")
/*
@从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());
}
}
这个方法,已经经多人验证了,我也在用这个方法,你试通后,马上揭贴吧。
[email protected]
倒是用
new String(part.getFileName().getBytes("iso-8859-1"),"gb2312")
就可以了