struts 2 使用ajax上传文件
我使用struts 2,包括ajax,上传文件,下载时一切正常,我得到文件,但响应页面,由上传后执行的操作返回 文件,完全扭曲了,它在我的base.js中返回一个错误:($.ajaxSetup({未定义) 这里调用的操作是为了保存我的文件
public String saveFile() throws Exception {
if(uploadFileName!=null){
String chemin=context.getRealPath("");
File dirWebapps = new File(chemin);
String fullFileName =myUrl+"/"+uploadFileName;
File theFile = new File(dirWebapps.getParent(),fullFileName);
FileUtils.copyFile(upload, theFile);
URL repertoire = theFile.getParentFile().toURL();
}
return "myPage";
}
,有人可以帮我
在 struts.xml 文件上传中定义一个 bean,如下所示:
和“myPage”包含
<%@ taglib prefix="s" uri="/struts-tags"%> <%@ page contentType="text/html; charset=utf-8"%> <%@ taglib prefix="sj" uri="/struts-jquery-tags"%> <script type="text/javascript" src="js/base.js"></script> <script type="text/javascript"> $(function(){ ///something }) </script> <s:form id="courrierModel" validate="true" theme="simple" cssStyle="margin:0;padding:0px" enctype="multipart/form-data" method="GET"> some content </s:form>
I use struts 2, including ajax, to upload a file, everything works when downloading, I get the file, but the response page,returned by the action executed after uploading
file, is completely distorted, it return an error in my base.js: ($. ajaxSetup ({is not defined)
Here the action called to save my file
public String saveFile() throws Exception {
if(uploadFileName!=null){
String chemin=context.getRealPath("");
File dirWebapps = new File(chemin);
String fullFileName =myUrl+"/"+uploadFileName;
File theFile = new File(dirWebapps.getParent(),fullFileName);
FileUtils.copyFile(upload, theFile);
URL repertoire = theFile.getParentFile().toURL();
}
return "myPage";
}
please,can someone help me
I define a bean in struts.xml file upload as follows:
and "myPage" contains
<%@ taglib prefix="s" uri="/struts-tags"%> <%@ page contentType="text/html; charset=utf-8"%> <%@ taglib prefix="sj" uri="/struts-jquery-tags"%> <script type="text/javascript" src="js/base.js"></script> <script type="text/javascript"> $(function(){ ///something }) </script> <s:form id="courrierModel" validate="true" theme="simple" cssStyle="margin:0;padding:0px" enctype="multipart/form-data" method="GET"> some content </s:form>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您所要做的就是返回一个状态为 200 的 http 标头。
例如代码:
All you got to do is return a http-header with status 200.
E.g. code :