public String picUpload(){
HttpServletResponse response=ServletActionContext.getResponse();
SimpleDateFormat sDateFormat;
Random r=new Random();
realpath=ServletActionContext.getServletContext().getRealPath("/"+laiyuang);
realpath=realpath+"/file/";
realpath=realpath.replace("\\", "/");
if(fileupload!=null){
File savedir=new File(realpath);
if (!savedir.isFile()){
new File(realpath).mkdir();
}
}
for(i=0;i<fileupload.length;i++){
new Thread(new MultipleUploadAction(fileupload[i],fileuploadContentType[i],fileuploadFileName[i],laiyuang,i,)
realpath,savePath400,savePath1024,response)).start();
}
return SUCCESS;
}
@Override
public void run() {
String extName=null;
if(fileuploadFileNamea.lastIndexOf(".")>=0){
extName=fileuploadFileNamea.substring(fileuploadFileNamea.lastIndexOf("."));
extName=extName.substring(1,extName.length());
}
String saveFile=realpath+nowTimeStr+rannum+i+"."+extName;
saveFile=saveFile.replace("\\", "/");
try{
FileUtils.copyFile(fileuploada, new File(saveFile));
}catch(Exception e){
e.printStackTrace();
}
PrintWriter out=null;
System.out.println(response);
response.setCharacterEncoding("utf-8");
response.setContentType("text/html");
try{
out=response.getWriter();
out.print(saveFile);
out.flush();
}catch(IOException e){
e.printStackTrace();
}finally{
out.close();
}
}
加上红色的就出问题了。
前台:
<script type="text/javascript">
function uploadImage(obj) {
$(document)
.ready(
function() {
alert("ee");
var options = {
url : "tool/picUpload.action",
type : "POST",
dataType : "script",
success : processJson,
error: eJson
};
$("#touxinagform").ajaxSubmit(options);
return false;
});
}
function processJson(msg){
alert(msg);
}
function eJson(){
alert("ttaa");
}
------解决思路----------------------
response.setContentType("text/html;charset=UTF-8");
------解决思路----------------------
加同步试试呗 不过我怀疑不是这里的问题 你用的是struts2吧 struts2是线程安全的 有报错信息吗?
------解决思路----------------------
out.flush(); 和 out.close(); 去掉试试 输出流会自动刷新和关闭的