xheditor实现上传
来源:互联网 发布:乔治敦大学知乎 编辑:程序博客网 时间:2024/05/07 05:17
package com.yuxuan.action;import java.io.File;import java.io.IOException;import org.apache.commons.io.FileUtils;import org.springframework.context.annotation.Scope;import org.springframework.stereotype.Component;import com.opensymphony.xwork2.ActionSupport;@Component@Scope("prototype")public class MessageAction extends BaseAction{private File filedata; public File getFiledata() {return filedata;}public void setFiledata(File filedata) {this.filedata = filedata;}public void upload() throws IOException{String fileName=filedata.getName().replaceFirst(".tmp", ".png");System.out.println(filedata);String pathString = this.httpServletRequest.getServletContext().getRealPath("/kk/")+"/"+fileName;File copyfile = new File(pathString);FileUtils.copyFile(filedata, copyfile);String url = "/BBS_FORJAVA/kk/";//String jsonsString = "{err:'"+errorString+"',msg:'"+url+fileName+"'}";String jsonsString = "{\"err\":\"\",\"msg\":\""+url+fileName+"\"}";httpServletResponse.getWriter().write(jsonsString);}}
注意
jsonsString格式
err:后面是空字符串,否则会出现接口错误。
url里面是"/项目名/文件夹名",如果只写文件夹名会出现叉子
不能返回 String jsonsString = "{\"err\":\"\",\"msg\":\""+pathString+"\"}";
会无法读取该图片的
jsp页面
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%><%@ taglib prefix="s" uri="/struts-tags" %> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><script type="text/javascript" src="${pageContext.request.contextPath}/xhEditor/jquery/jquery-1.4.4.min.js"></script> <script type="text/javascript" src="${pageContext.request.contextPath}/xhEditor/xheditor-1.2.1.min.js"></script> <script type="text/javascript" src="${pageContext.request.contextPath}/xhEditor/xheditor_lang/zh-cn.js"></script><title>我的短信-我的应用</title></head><body><form id="frmDemo" method="post" action="show.php"><s:textfield label="收件人"></s:textfield><br><s:textfield label="主题"></s:textfield><br><s:textarea id="elm1" name="elm1" rows="12" cols="80" style="width: 80%" cssClass="xheditor">test</s:textarea></form><script type="text/javascript">$('#elm1').xheditor({tools:'full',skin:'default',showBlocktag:true,internalScript:false,internalStyle:false,sourceMode:true,forcePtag:true,upImgUrl:"messageAction_upload",upImgExt:"tmp,jpg,jpeg,gif,png",onUpload:insertUpload});//文件上传回调函数 function insertUpload(data){ var msg=data.toString(); alert(data); $("#elm1").append(msg); } </script></body></html>
- xheditor实现上传
- xheditor编辑器上传功能实现
- xhEditor struts2实现图片上传
- xheditor+struts 实现图片上传
- 关于使用xheditor实现图片上传
- Java 实现 xhEditor 文件上传处理
- Laravel5.2中使用xheditor编辑器实现上传图片功能
- xheditor图片上传
- xheditor struts2 上传文件
- struts2+xheditor+上传图片功能
- dwz xheditor编辑器文件上传
- spring mvc+xheditor图片上传
- 配置xheditor图片上传功能
- dwz xheditor编辑器文件上传
- xhEditor在线编辑器学习笔记(1)---用Struts2+ajax实现图片上传
- xhEditor
- xhEditor
- xheditor
- [另类思考] 简单的问题复杂着解决
- yum安装Apache,Mysql,PHP
- poj 3842 -- An Industrial Spy ( 全排列 )
- maven使用
- Junit4
- xheditor实现上传
- vb 内存释放
- Versions-SVN客户端经常在更新时报错Working copy lock
- 程序员性格怪癖是才华横溢的表现,还是危险分子的征兆?
- oracle中replace函数
- 快速编译
- 《游戏编程入门》学习笔记6——帧率控制、用文本显示调试信息
- C/C++中extern关键字详解
- OpenERP新版发布