【问题标题】:struts 2 using ajax to upload a filestruts 2 使用ajax 上传文件
【发布时间】:2011-12-14 02:16:39
【问题描述】:

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

【问题讨论】:

  • 答案和你上次问的一样:)
  • 我试着用另一种方式说出来,因为答案对我没有帮助
  • 这段代码应该是文件上传。请在结果名称 myPage 中包含您的 struts.xml 和您指向的 jsp 的内容。
  • @user1005045 来吧,把它放在问题中——我们怎么能读懂它?

标签: java ajax file-upload struts2


【解决方案1】:

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

例如代码:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-10-17
    • 1970-01-01
    • 2013-05-13
    • 1970-01-01
    • 1970-01-01
    • 2011-01-08
    相关资源
    最近更新 更多