ajaxFileUpload上传文件时,后台action不执行也不报错,回调函数的success

d-sunshine 2015-11-05 03:39:18
$("#buttonUpload").click(function(){
$.ajaxFileUpload({
url:'/uploadLicense.action',
secureuri:false,
fileElementId:'fileToUpload',
dataType:'text',
success:function(data){
if(data.indexOf("ok") != -1){
alert(data);
// alert("授权成功!");
window.parent.location.href="/pages/common/login.jsp";
}
else{
alert(data);
}
},
error:function(){
}

});
//return false;
});

<input id="fileToUpload" type="file" size="20" name="Filedata" >
<button id="buttonUpload">上传</button>
上面是我的请求上传文件的代码,下面是后台的action,在action的类中,我也设置了Filedata的set和get方法了,以前都是这样用的,现在突然不行了,希望大家帮帮忙啊
@Action(value="uploadLicense")
public void uploadLicense() throws IOException{
//存放到指定目录
FileOutputStream fos = null;
FileInputStream fis = null;
try {
fos = new FileOutputStream(SystemInit.getRootPath()+"license/licence.xml");
fis = new FileInputStream(Filedata);
IOUtils.copy(fis, fos);
fos.flush();
fos.close();
fis.close();
} catch (Exception e) {
e.printStackTrace();
}
//验证license
String result = ScmsUtil.checkLicense();
//Struts2Utils.renderText(result);
response.setCharacterEncoding("utF-8");
PrintWriter out = response.getWriter();
out.write(result);

}
...全文
623 13 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
ab637800 2015-11-06
  • 打赏
  • 举报
回复
看你DATA的内容 你后台报错了啊 你把 PrintWriter out = response.getWriter(); out.write(result); 输出流去掉 你看看你后台显示什么错误。
baidu_32608009 2015-11-06
  • 打赏
  • 举报
回复
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> <% String path = request.getContextPath(); String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <base href="<%=basePath%>"> <title>My JSP 'index.jsp' starting page</title> <meta http-equiv="pragma" content="no-cache"> <meta http-equiv="cache-control" content="no-cache"> <meta http-equiv="expires" content="0"> <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"> <meta http-equiv="description" content="This is my page"> <!-- <link rel="stylesheet" type="text/css" href="styles.css"> --> <link href="<%=path %>/uploadify/uploadify.css?v=1.1" rel="stylesheet" type="text/css" /> <script type="text/javascript" src="<%=path %>/js/jquery-1.7.1.min.js"></script> <script type="text/javascript" src="<%=path %>/uploadify/jquery.uploadify.js"></script> <script type="text/javascript"> $(document).ready(function(){ $(".uploadify4").uploadify({ //指定swf文件 'swf': 'uploadify/uploadify.swf', //后台处理的页面 'uploader': 'uploadify/upload_json.jsp', //按钮显示的文字 'buttonText': '上传图片', //显示的高度和宽度,默认 height 30;width 120 //'height': 15, //'width': 80, //上传文件的类型 默认为所有文件 'All Files' ; '*.*' //在浏览窗口底部的文件类型下拉菜单中显示的文本 'fileTypeDesc': 'Image Files', //允许上传的文件后缀 'fileTypeExts': '*.*', //发送给后台的其他参数通过formData指定 //'formData': { 'someKey': 'someValue', 'someOtherKey': 1 }, //上传文件页面中,你想要用来作为文件队列的元素的id, 默认为false 自动生成, 不带# //'queueID': 'fileQueue', //选择文件后自动上传 'auto': true, //设置为true将允许多文件上传 'multi': true, onUploadSuccess: function(file,data,respone){ debugger; alert(data); } }); }); </script> </head> <body> <input type="file" name="uploaddify" id="uploadify" class="uploadify4"/> <input type="file" name="uploaddify" id="uploadify1" class="uploadify4"/> </body> </html>
AlexMoonshadow 2015-11-06
  • 打赏
  • 举报
回复
仔细核对配置文件跳转部分,action名,方法名都对不对,其他都正常这个不行,后台action方法都进不去只能是页面或者配置文件有问题。
jj0701 2015-11-05
  • 打赏
  • 举报
回复
url:'/uploadLicense.action', secureuri:false, fileElementId:'fileToUpload', dataType:'text', type:'post', 加上最后的type:'post',再试试呢
jj0701 2015-11-05
  • 打赏
  • 举报
回复
type 当要提交自定义参数时,这个参数要设置成post
d-sunshine 2015-11-05
  • 打赏
  • 举报
回复
引用 5 楼 sinat_31535993 的回复:
error:function(){
}
在这个方法里面可以取得,你是怎么错的

回调函数执行的是success,因为data是在success输出的,data的内容是下面的
d-sunshine 2015-11-05
  • 打赏
  • 举报
回复
引用 4 楼 u010271222 的回复:
看是不是你的配置文件有问题
配置文件没有问题的,因为所有的action都是这样写的 其他的都能用,只有 这个不行,愁死我了
d-sunshine 2015-11-05
  • 打赏
  • 举报
回复
引用 1 楼 ab637800 的回复:
你打个断点看看,能进入你后台的方法不,不能就是路径错了啊


打了断点了 根本就进不去这个action,出现的错误是
sinat_31535993 2015-11-05
  • 打赏
  • 举报
回复
error:function(){ } 在这个方法里面可以取得,你是怎么错的
Me_Mr_Wang 2015-11-05
  • 打赏
  • 举报
回复
看是不是你的配置文件有问题
d-sunshine 2015-11-05
  • 打赏
  • 举报
回复
好像是action不可达什么的错误,但是回调函数执行的是success啊 因为data是在success中输出的
d-sunshine 2015-11-05
  • 打赏
  • 举报
回复
打了断点了 根本就进不去这个action,出现的错误是
ab637800 2015-11-05
  • 打赏
  • 举报
回复
你打个断点看看,能进入你后台的方法不,不能就是路径错了啊

81,122

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧