用gb2312就正常。换成utf-8就乱码(smartupload) 在线等
如果2个页面都是gb2312的话。得到的是正常的。
2个页面换成UTF-8就是乱码。哪位高手能告诉点细节。为什么这样?
<%@ page language="java"
pageEncoding="utf-8"%>
<%@page import="java.util.Date"%>
<%@page import="java.io.InputStream"%>
<%@page import="java.io.PrintWriter"%>
<%@page import="java.text.SimpleDateFormat"%>
<%@page import="java.util.Properties"%>
<%@page import="java.util.Enumeration"%>
<%@page import="com.jspsmart.upload.SmartFiles"%>
<%@page import="com.jspsmart.upload.SmartUpload"%>
<%@page import="com.jspsmart.upload.SmartFile"%>
<%@ page import="com.util.*"%>
<%@page import="java.net.URLDecoder"%>
<HTML>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>文件上传</title>
<link rel="stylesheet" href="lucy.css" type="text/css">
<%
SmartUpload su = new SmartUpload();
String path = null;
String fileName="";
int flag=0;
try {
//request.setCharacterEncoding("utf-8");
//response.setContentType("text/html; charset=utf-8");
su.initialize(pageContext);
su.upload();
su.setMaxFileSize(10240);
su.setTotalMaxFileSize(20480);
su.setAllowedFilesList("doc,txt,jpg,gif,pdf");
su.setDeniedFilesList("exe,bat,com,htm,html");
if(path==null||path.equals("")){
com.tool.Tool tool = new com.tool.Tool();
path = tool.getPath();
}
for(int i=0; i<su.getFiles().getCount(); i++){
SmartFile file1 = su.getFiles().getFile(i);
if (file1.isMissing()){ //文件存在则进行判断
System.out.println("文件不存在");
continue;
}else{
String fileNameSN = file1.getFileName();
//fileNameSN = Util.convertChinese(fileNameSN);
//fileNameSN = new String(fileNameSN.getBytes("utf-8"),"gb2312");
//fileNameSN = new String(fileNameSN.getBytes("ISO-8859-1"),"utf-8");
System.out.println("fileNameSN:"+fileNameSN);
Date date = new Date();
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMdHms");
String dateStr = dateFormat.format(date);
fileName = dateStr+"."+file1.getFileExt();
//System.out.println(path+fileName);
file1.saveAs(path+fileName,su.SAVE_VIRTUAL);
flag+=1;
String tarobj,fn,sn;
int fsize;
tarobj = Util.convertChinese(request.getParameter("tagobj"));
fn = fileName;
sn = fileNameSN;
//sn = String.format("%c",sn);
fsize=file1.getSize()/1024;
if (fsize == 0){
fsize = 1;
}
%>
<script>
window.opener.fnAttachfile('<%=Util.convertChinese(request.getParameter("ta"))%>','<%=fn%>','<%=sn%>','<%=fsize%>')
window.close()
</script>
<%
}
}
} catch (Exception e) {
//e.printStackTrace();
}
%>
<script language=javascript>
function f_check() {
if (document.all.SourceFile.value=="")
{
alert ("请选择文件!")
return false
}
else {
document.all.f1.submit()
}
}
</script>
</head>
<BODY BGCOLOR="white" topmargin="0" leftmargin="0" marginwidth="0" marginheight="0" >
<form method=post ENCTYPE="multipart/form-data" onsubmit="return f_check();" name="f1" >
<table width="100%" border="1" cellspacing="0" cellpadding="2" align="center" bordercolordark="#ffffff" bordercolorlight="#000000">
<tr>
<td bgcolor="#B58A00" height="21">
<div align="center"><font color="#FFFFFF" size="2"><b>文件上传</b></font></div>
</td>
</tr>
<tr>
<td>
<table width="100%" border="0" cellspacing="0" cellpadding="0" style="border:solid black 1px" bordercolorlight="#000000" bordercolordark="#FFFFFF" class="9p" align="center">
<tr>
<td align="center" height="30">
<input type="file" name="SourceFile">
<input type="hidden" name="sfname" >
</td>
</tr>
<tr>
<td align="center" height="30">
<input type="submit" value="开始上传" name="butston" />
<input type="button" value="关闭窗口" onClick="window.close()" name="buttocn">
</tr>
</table>
</td>
</tr>
</table>
<br>
<span align="center">注:大小请控制在 2000K 内。</span>
</form>
</BODY>
</HTML>