Strut架构中上传的中文文件名乱码问题?
Action中的方法代码如下:
public ActionForward execute ( ActionMapping mapping ,
ActionForm form ,
HttpServletRequest request ,
HttpServletResponse response )
throws Exception
{
HttpSession session = request.getSession() ;
DynaActionForm df = ( DynaActionForm ) form ;
String fName = ( String ) df.get( "fname" ) ;
FormFile formFile = ( FormFile ) df.get( "upfile" ) ;
if ( fName.length() == 0 )
{
fName = StringUtil.cn( formFile.getFileName() ) ;
/*
不管怎么转,转成哪个字符集都是乱码
*/
}
String msg = "上传成功!" ;
if ( formFile.getFileData().length == 0 )
{
msg = "文件为空!" ;
}
else
{
Document doc = new Document() ;
doc.setName( fName ) ;
doc.setFilename( StringUtil.cn( formFile.getFileName() ) ) ;
doc.setExt( formFile.getContentType() ) ;
doc.setContent( formFile.getFileData() ) ;
doc.setType( "2" ) ;
doc.setUploadDatetime( new java.util.Date() ) ;
doc.setUploader( uc.getUser().getName() ) ;
doc.setSubType( nodeName ) ;
doc.setKind( kind ) ;
doc.setAppId( appId ) ;
DocMgt dm = new DocMgt() ;
dm.addDoc( doc ) ;
System.out.println( "finish save attachment" ) ;
}
request.setAttribute( "msg" , msg ) ;
return ( mapping.findForward( "filelist" ) ) ;
}
其中StringUtil.cn()方法是转换成GB2312字符集的,不过我试了好几种字符的转换都不行,请高手帮忙