栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

文件上传| 没有页面刷新| struts2 | 没有闪光灯

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

文件上传| 没有页面刷新| struts2 | 没有闪光灯

我正在使用相同的插件,对我来说效果很好。我在您的代码中看到的第一个问题是您尚未设置要提交的上传按钮的类型。

<button id="px-submit" type="submit">Upload</button>

希望这应该解决null指针除外。另外,如该插件的文档中所述,您需要返回一个json字符串

<div id='message'>success message</div>

成功上传。因此,您需要更改struts.xml映射。尝试此操作,如果您遇到任何其他问题,请立即与我联系。编辑:好的,这是您要求的我的代码

JSP

<form action="uploadImage" method="post" enctype="multipart/form-data">   <input type="file" name="image"  multiple/>   <button id="px-submit" type="submit">Save all images</button>   <button id="px-clear" type="reset">Clear all</button></form>$('.fileUpload').fileUploader({          autoUpload: false,          buttonUpload: '#px-submit',          buttonClear: '#px-clear',});

动作课

您需要返回流结果。我使用的插件(struts2的jQuery插件),它采用的是变化很好地照顾,但你
必须使用它仅仅是因为这一要求,而不是我给你返回流结果的代码,而无需使用任何插件。(摘自从这里)

public class UploadImageAction extends ActionSupport{        private File image;        private String imageContentType;        private String imageFileName;        //getter/setter for these        public String execute() {         String status="";      try{   //save file pre here  status="<div id='message'>successfully uploaded</div>"; //on success         inputStream = new StringBufferInputStream(status);        }catch(WhateverException e){         status="<div id='status'>fail</div><div id='message'>Your fail message</div>"; //on error         inputStream = new StringBufferInputStream(status);         //other pre        }        return SUCCESS;    }    private InputStream inputStream;    public InputStream getInputStream() {       return inputStream;    }}

struts.xml

<action name="fileUpload" >      <result type="stream">      <param name="contentType">text/html</param>      <param name="inputName">inputStream</param>    </result>  </action>


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/379958.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号