java.io.IOException: 远程主机强迫关闭了一个现有的连接。 突然之间就报错了。。。。
$(function () {
idss = getQueryString('id');
load_list();
var options={
url:"${pageContext.request.contextPath }/license/save",
type:"post",
success:function(data){
//保存后的回调
$("#addzzdiv").modal("hide");
layer.msg('已保存!',{icon: 6,time:1000});
load_list();
}
};
$("#formid").submit(function() {
$(this).ajaxSubmit(options);
return false;
});
});
@At
@AdaptBy(type = UploadAdaptor.class, args = { "ioc:myPicUpload" })
public Object save(@Param("..")License license ,@Param("img")TempFile [] tempfile,HttpSession session){
if(Strings.isBlank(license.getLicenseId())){
license.setLicenseId(new GUID().getguid());
if(tempfile != null && tempfile.length>0){
String oldName=""; //原文件名
String uuidName =""; //自命名文件名
String uuidName1="";
for(TempFile t : tempfile){
oldName = t.getSubmittedFileName();
uuidName= (new GUID().getguid()) + oldName.substring(oldName.lastIndexOf("."));
String savePath = session.getServletContext().getRealPath("/img/"+uuidName);
uuidName1 += uuidName+",";
InputStream input = null;
OutputStream out = null;
try {
input = t.getInputStream(); //数据流(务必自行关闭)
out = new FileOutputStream(new File(savePath));
byte[] buffered = new byte[1024 * 1024 * 2];
int length = 0; // 已经成功读取的字节的个数
while ((length = input.read(buffered)) != -1) {
out.write(buffered, 0, length);
}
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
input.close();
out.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
uuidName1 = uuidName1.substring(0, uuidName1.length()-1);
license.setImg(uuidName1); //图片路径放入数据库
}
this.licenseService.save(license);
}else{
if(tempfile != null && tempfile.length>0){
String oldName=""; //原文件名
String uuidName =""; //自命名文件名
String uuidName1="";
for(TempFile t : tempfile){
oldName = t.getSubmittedFileName();
uuidName= (new GUID().getguid()) + oldName.substring(oldName.lastIndexOf("."));
String savePath = session.getServletContext().getRealPath("/img/"+uuidName);
uuidName1 += uuidName+",";
InputStream input = null;
OutputStream out = null;
try {
input = t.getInputStream(); //数据流(务必自行关闭)
out = new FileOutputStream(new File(savePath));
byte[] buffered = new byte[1024 * 1024 * 2];
int length = 0; // 已经成功读取的字节的个数
while ((length = input.read(buffered)) != -1) {
out.write(buffered, 0, length);
}
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
input.close();
out.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
uuidName1 = uuidName1.substring(0, uuidName1.length()-1);
license.setImg(uuidName1); //图片路径放入数据库
}else{
License license1 = this.licenseService.getById(license.getLicenseId());
license.setImg(license1.getImg());
}
this.licenseService.update(license);
}
return true;
}