gpt4 book ai didi

java - struts 2 使用ajax上传文件

转载 作者:行者123 更新时间:2023-11-30 04:58:04 24 4
gpt4 key购买 nike

我使用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>

最佳答案

您所要做的就是返回一个状态为 200 的 http header 。

例如代码:

<action name="uploadaction" class="actions.UploadAction">
<result name="success" type="httpheader">
<param name="status">200</param>
</result>
</action>

关于java - struts 2 使用ajax上传文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7875410/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com