struts2 jquery ajaxfileupload 插件对返回的json下载问题!!
*.java
public String uploadimghead() throws IOException{
user = (User) ActionContext.getContext().getSession().get("user");
PrintWriter out = ServletActionContext.getResponse().getWriter();
try {
if(user!=null){
if(file!=null){
String fileSuffix = fileFileName.substring(this.fileFileName.lastIndexOf("."),fileFileName.length());
String s = "upload/user/temp-head/";
String url = context.getRealPath("/");
String fileName = ImgUpload.uploadImage(file, fileSuffix, url+s, user.getId());
ImgUpload.alterSize(url+s+fileName,url+s,fileName,300,275);//图片比例缩放下
ActionContext.getContext().getSession().put("temp-head", fileName);
out.write(s+fileName);
out.flush();
out.close();
}
}else{
out.write("nouser");//用户不存在
out.flush();
out.close();
}
} catch (Exception e) {
out.write("error");
out.flush();
out.close();
}finally{
return "success";
}
}
*.js
$.ajaxFileUpload({
url:"user/reg!uploadimghead.json?s"+new Date().valueOf(),
secureuri:false,
dataType: 'json',
fileElementId:"file1",
success: function (data, status)
{
var t = $(data).text();
if(t!="error"||t!="nouser"){//服务器错误
if(t==""){
regHeadModefind(data);//头像设置
}else{
regHeadModefind(t);//头像设置
}
resetUpload1(); //头像上传成功
}else{
$('#msgsuccess').html("");
$('#msgerror').html('头像上传失败!请重新上传图片!');
location.href="user!manager?vid=info";//刷新页面
}
}, error: function (data, status, e)
{
alert("上传失败...");
}
})
返回json下载问题!!!!!!!!!
我的QQ是348059300在线等!!!!!!!!!!