此前的一篇文章介绍了xheditor使用servlet实现上传的接口,但在Struts2的应用中由于Struts2封装了request和response使得,此前写的程序无法获取数据。可能通过一些修改可以另前面的程序继续使用,但是我这里介绍一种完全使用Struts2标准的xheditor配置方法。其实这个方法在xheditor的官方论坛有讲过,但是由于讲述并不清楚,可能对于一些新手使用并不方便,我这里结合我使用的方法,整理出来代码供大家参考。
1、首先是在textarea中配置class
class=“xheditor {skin:'o2007blue',html5Upload:false,upMultiple:'1',upImgUrl:'Upload.do',upImgExt:'jpg,jpeg,gif,bmp,png',upLinkUrl:'Upload.do',upLinkExt:'zip,rar,txt,docx,doc,xls,xlsx,pdf'}"
注意到我这里的上传的Action是Upload.do
2、接着下来配置Struts.xml来解析配置
<action name="Upload" class="com.webapp.action.XheditorUploadAction" method="uploadPicture">
<result> /SuccessUpload.jsp </result>
</action>
这个xml配置主要是做一些简单的返回,最后我会具体的写明白返回的jsp应该怎么写
3、这步就主要编写Upload的Action
package com.webapp.action;
import java.awt.Image;
import java.io.File;
import javax.imageio.ImageIO;
import org.apache.commons.io.FileUtils;
public class XheditorUploadAction extends PersonCommonAction {
private File filedata;
private String filedataContentType;
private String filedataFileName;
private String err;
private String msg;
private String message;
private String fileExt = "jpg,jpeg,gif,bmp,png";
public String uploadPicture() throws Exception {
String saveRealFilePath = getSession().getServletContext().getRealPath("/") + "resources/XheditorUpload/" ;
File fileDir = new File(saveRealFilePath);
if (!fileDir.exists()) {
fileDir.mkdirs();
}
File savefile;
savefile = new File(saveRealFilePath + filedataFileName);
FileUtils.copyFile(filedata,savefile);
msg = "resources/XheditorUpload/" + filedataFileName;
err="";
printInfo( err, msg);
return SUCCESS;
}
public void printInfo(String err,String newFileName) {
message = "{\"err\":\"" + err + "\",\"msg\":\"" + newFileName
+ "\"}";
}
public String uploadJsp()
{
return SUCCESS;
}
public File getFiledata() {
return filedata;
}
public void setFiledata(File filedata) {
this.filedata = filedata;
}
public String getFiledataContentType() {
return filedataContentType;
}
public void setFiledataContentType(String filedataContentType) {
this.filedataContentType = filedataContentType;
}
public String getFiledataFileName() {
return filedataFileName;
}
public void setFiledataFileName(String filedataFileName) {
this.filedataFileName = filedataFileName;
}
public String getErr() {
return err;
}
public void setErr(String err) {
this.err = err;
}
public String getMsg() {
return msg;
}
public void setMsg(String msg) {
this.msg = msg;
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
}
这里重点理解的是filedata,因为xheditor会把filedata的值写到值栈里边,而Struts2会自动获取这个值
4、接着是SuccessUpload.jsp
<%@ taglib prefix="s" uri="/struts-tags" %>
<s:property value="message" escape="false"/>
这个很简单,就在jsp页面里边写两行就可以了,其实这里是把message的值打印出来,返回给xheditor而已
分享到:
相关推荐
NULL 博文链接:https://hacker507.iteye.com/blog/1679273
参考博文:http://blog.csdn.net/itmyhome1990/article/details/38491205
用于xheditor编辑器上传功能的配置文件 upload.aspx,直接下载拷贝到项目根目录下即可。 里面的该行: string attachdir ="../upload"; 是上传路径,根据实际引用xheditor的页面位置,要进行相应的修改,要不然无法...
xheditor1.1.13在ASPNET开发网站中的使用,C#,vs2013,实现在线编辑html流,包括本地图片的上传,非常简洁,稍加扩充可用于自己的网站(如博客网站等) 本例xheditor控件采用自定义模式,可参照进行重新配置,实现控件的增减,...
基于轻量级的JQuery的xheditor编辑器+jsp实现图上传功能
xheditor在asp.net中使用时,如果textbox控件在UpdatePanel使用无刷新提交时,原先的样式就丢失,此时需要使用脚本重新加载。在本文件在包含完整的xheditor-1.1.13及其demos。在demos文件夹里的Default2.aspx及...
jquery xheditor是jquery中较好的编辑器插件,而jquery.uploadify也是jquery实现文件上传很优秀的插件,本项目实例解决了两个插件文件上传的问题,对于应用学习两个插件,实现文件上传,具有很好的参考价值,同时本例子是...
此文档为Struts架构下的XhEditor的完整案例,可以直接使用。
xhEditor编缉器,用于java开发时,上传文件,同时解决了在火狐上使用时报错的问题,主要是因为火狐上传时使用的是HTML5,如何解决请花1分吧!! 记得把xheditor里的上传改成servlet的路径呀!!
2. xhEditor进阶使用 2.1. 进阶使用指导 2.2. 初始化参数列表 2.3. API函数接口列表 2.4. 上传程序开发规范 2.5. 插件开发指南 2.6. 皮肤设计指南 2.7. 关于二次开发 2.1. 进阶使用指导 阅读本章节请先阅读:...
xhEditor文本编辑器在asp.net中的应用
在xheditor在线编辑器下,ASP提交远程图片自动上传到服务器
上次发了个资源解决了xheditor在asp.net中使用时,如果textbox控件在UpdatePanel使用无刷新提交时,原先的样式就丢失的问题。后来又发现了在DropDownList使用服务端的ontextchanged事件回传后,控件值的丢失与获取不...
struts1_xheditor web编辑器源代码
我已配置好,直接使用就可以了,最好最轻便的编辑器xheditor,支持ajax本地上传文件【上传格式也很方便的自定义】,绝对错不了~~~
XHEditor是一款JS+JQuery的编辑器,前台使用方便,占有资料小。本例有具体的上传代码,适合XHEditor的入门
xheditor-1.2.1 上传图片 jquery版本:jquery-1.11.0 ASP.NET环境
xheditor jsp完整实例 根据 http://xheditor.com/ 官网开发的jsp版本的实例、 部署即可运行。 希望网友们喜欢。
xheditor-1.1.4 在线编辑器 自己感觉很不错!
xheditor-1.1.14.zip