最近一个项目中因为框架的原因,很多文本编辑器都不兼容,最后找到xheditor,这个富文本编辑器的确不错,功能基本都能满足,只是上传图片的java接口需要自己写,因此,测试了两种方法,最终成功。分享给大家。

xheditor官方给出了上传接口。因此我们只需要调用自己的Action按照它指定的json格式返回一个json数据就可以了。aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAABMMAAACFCAIAAADZxagOAAAgAElEQVR4nO2cvbE1tdJGdwREgE0SeKRACkRAQJikQBRU4WDgkwEeRTGfQd39zSt1P/20Zmb/nLOWQc2WWv2nHo36cjm3DQAAAAAAAKDD7dkOAAAAAAAAwJtBJwkAAAAAAAA96CQBAAAAAACgB50kAAAAAAAA9KCTBAAAAAAAgB50kgAAAAAAANCDThIAAAAAAAB60EkCAAAAAABADzpJAAAAAAAA6EEnCQAAAAAAAD3oJAEAAAAAAKAHnSQAAAAAAAD0WOkkb7fb7VYs3MsI+WFKa77Plg7cco4E1VpiemvGctBVAAAAAACAE3mJTtLs+srebF4r3NCmW8KlkyIDjqRvHQAAAAAA4AFc0kkO3VTY+ZRTs0KzSctmB8mFNsxs+Xz9c0StVQAAAAAAAE/h2k6ylM96y1BsaLfmLjQcn8VmnVpSeCv8dNSGLumsmq4CAAAAAABcx3onWXZow4ivalarx0OdZhShJ84SX7LrwyxwH/cTCwAAAAAAcB0n/zvJsjPM+jfH4qxEt17aerZ2LSjT4VBgsK4dE0YBAAAAAAAew+X/71YhPHdETi+3GU1X1qQJybL38+OaZ7WfpfJuRJlXAAAAAAAAp/CgTjLrhcxezhnJBjOHhVgWYNnLaW+FoUzAlB/shl4BAAAAAACcxSP+4o45KNok0TdqsdtEudyMSwgPgZSSpdo5iiwoAAAAAACAB/DQfydZqnL6rlKt2SJ2O8nQ1WWxIQrH1Tn2UhsAAAAAAMAVnNBJli2Z2Unen8sWMVzl+xOOZIPLGm4ToXBIqVa4lIUAAAAAAABwFlbXIXqesP8x+7Q1DZme+afws9WGtcLJVM3WQ1sCM0sAAAAAAABXQx8CAA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rRXwnkRsnbeDEo4f2JKAQAAAAA+Ni99S86aw+OdZPZvn3TPo5sTp1+abWVN1zwrprS5reLqTjILJPTW2RTtkuOhkHQGAQAAAAA+Oa9+S77ici9ai+OdZKsdmi2KxtJsQYfBI52kEBimTGeyKeGS43OZYb2tg6S5cQAAAAAAn5lXvyX7neRy16Q1i+ZqsGi2K4O3Zic5D2rTzlSpdlYSJsF0u/RTY7oUqjU98QcBAAAAAD45r35LvjcqZY/R/ddHTtuwt+44WZoo+0+zJRumRE6E25nC2b3MVigQ2h3kfWfEbKlQCJSDazkEAAAAAPgkvPot+bp7vO5Lt6pVc3o2s1nNHDUN6/sAAAB9SURBVBAazk2LtnvEVhbUnD2H2VUtKcQyb2c/l2MHAAAAAPjAcFEGAAAAAACAHnSSAAAAAAAA0INOEgAAAAAAAHrQSQIAAAAAAEAPOkkAAAAAAADoQScJAAAAAAAAPegkAQAAAAAAoAedJAAAAAAAAPSgkwQAAAAAAIAe/weKMfnQduIKtAAAAABJRU5ErkJggg==" alt="" />

 

一、使用servlet时的实现方式,servlet的实现方式需要引入commons-fileupload-1.3.1.jar包。主要是用来解析前台传过来的请求。

  1、前台页面的写法,当然要引入xheditor啦,这里我就不写了。这里主要是upImgUrl要写上你后台的Servlet。

<textarea class="editor" name="articleContent" rows="35" cols="100" style="z-index:99;"
upImgUrl="UploadFileServlet" upImgExt="jpg,jpeg,gif,png" >
${article.articlecontent }
</textarea>

2、后台servlet的写法。配置文件中我也省略了,这里仅仅是一个Servlet。需要注意的,这里要引入commons-fileupload-1.3.1.jar包来解析请求。

package com.zk.web.action;

import java.io.File;
import java.io.IOException;
import java.util.Iterator;
import java.util.List; import javax.servlet.ServletConfig;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import org.apache.commons.fileupload.FileItem;
import org.apache.commons.fileupload.disk.DiskFileItemFactory;
import org.apache.commons.fileupload.servlet.ServletFileUpload; public class UploadFileServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
private ServletContext sc; public void init(ServletConfig config) {
sc = config.getServletContext();
} protected void doGet(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
this.doPost(request, response);
} protected void doPost(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
ServletOutputStream out = response.getOutputStream();
request.setCharacterEncoding( "utf-8" );
response.setHeader("Content-Type" , "text/html");
String returnPath = ""; DiskFileItemFactory factory = new DiskFileItemFactory();
ServletFileUpload upload = new ServletFileUpload(factory);
try {
List items = upload.parseRequest(request);
Iterator iter = items.iterator();
while (iter.hasNext()) {
FileItem item = (FileItem) iter.next();
System.out.println("上传文件的大小:" + item.getSize());
System.out.println("上传文件的类型:" + item.getContentType());
System.out.println("上传文件的名称:" + item.getName()); returnPath = "images/"+item.getName();
//这里是取得项目地址
File forder = new File(sc.getRealPath("/")+"images/");
            //判断文件夹是否存在
if (!forder.exists()) {
forder.mkdir();
} File file = new File(sc.getRealPath("/")+"images/"+item.getName());
item.write(file);
System.out.println("上传文件成功!");
}
} catch (Exception e) {
e.printStackTrace();
System.out.println("上传文件失败");
} //这里是关键,返回上传图片存储在服务器的地址。路径根据自己项目的路径调整。
out.print("{'err':'','msg':'"+ returnPath.replace("\\", "/")+"'}"); } }

二、使用spring mvc时的实现方式。uploadImage就是一个Action,

  1、前台页面的写法,同样要引入xheditor啦,我也省略了,这里主要是upImgUrl要写上你后台的Action。

<textarea class="editor" name="articleContent" rows="35" cols="100" style="z-index:99;"
upImgUrl="uploadImage.do" upImgExt="jpg,jpeg,gif,png" >
${article.articlecontent }
</textarea>

2、后台Action的写法,这里是使用的是sping mvc框架。

/**
* 文本编辑器上传图片
* @param request
* @param response
* @return
* @throws Exception
*/
public void uploadImage(HttpServletRequest request,
HttpServletResponse response)throws Exception{
ServletOutputStream out = response.getOutputStream();
request.setCharacterEncoding( "utf-8" );
response.setHeader("Content-Type" , "text/html"); CommonsMultipartResolver commonsMultipartResolver = new CommonsMultipartResolver(
request.getSession().getServletContext());
// 设置编码
commonsMultipartResolver.setDefaultEncoding("utf-8");
if (commonsMultipartResolver.isMultipart(request)) {
MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
MultipartFile image = multipartRequest.getFile("filedata");
String url = "images"+File.separator+Tool.dateToString(new Date(), "yyyyMMdd")+File.separator;
       //这里可以从项目中取得你项目根目录的地址
String filePath = "D:/"+url;
Random r = new Random();
if(image != null && !image.isEmpty()){
InputStream xtins = image.getInputStream();
String hj = new String(image.getOriginalFilename().getBytes("ISO-8859-1"),"UTF-8");
hj = hj.split("\\.")[1];
          //这里用来生成文件名
String fileName = Tool.dateToString(new Date(), "yyyyMMddHHmmss")+r.nextInt(1000)+"."+hj;
saveInputStreamToFile(filePath, fileName, xtins);
          //这里是用来返回给xheditor的
out.print("{'err':'','msg':'"+ (url+fileName).replace("\\", "/")+"'}");
}
}
} /**
* 保存文件流到指定路径
* @param filePath
* @param fileName
* @param inputStream
* @throws Exception
*/
public void saveInputStreamToFile(String filePath, String fileName,
InputStream inputStream) throws Exception {
OutputStream os = null;
try {
File forder = new File(filePath);
if (!forder.exists()) {
forder.mkdir();
}
File file = new File(filePath + fileName);
os = new FileOutputStream(file);
int bytesRead = 0;
byte[] buffer = new byte[8192];
while ((bytesRead = inputStream.read(buffer, 0, 8192)) != -1) {
os.write(buffer, 0, bytesRead);
}
os.close();
inputStream.close();
} catch (Exception ex) {
ex.printStackTrace();
throw ex;
} finally {
if (inputStream != null) {
inputStream.close();
}
if (os != null) {
os.close();
}
}
}

xheditor上传图片的java实现的更多相关文章

  1. 手机端上传图片及java后台接收和ajaxForm提交

    有很多微信开发的项目在手机端需要传图片,但是又不想调用微信的上传图片接口,于是采取了如下做法: 使用ajaxForm提交文件所需js:jquery.form.js 页面代码: <%@ page ...

  2. xheditor上传图片配置

    二. 源码: <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Xeditor.a ...

  3. ios客户端base64上传图片到java服务器遇到的问题

    由于base64位包含了“+”和“\”两个特殊符号,导致ios编码后上传图片到服务器,服务器解码以后的值会不一致,导致图片损坏. 解决办法:重写Base64类,用“(”和“)”替换“+”和“\”两个特 ...

  4. iOS用AFN上传图片到java后台

    -(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event { AFHTTPSessionMana ...

  5. Android使用xUtils3上传图片报错解决:java.lang.ArrayIndexOutOfBoundsException: 70918

    今天在使用安卓xUtils3框架配合SmartUpload框架上传图片到Java服务端时,遇到了一个莫名其妙的错误: 安卓端代码如下: 似乎并没有发现什么问题,以前在用xUtils2.6老版本时也是这 ...

  6. 网络编程3--毕向东java基础教程视频学习笔记

    Day24 01 TCP上传图片02 客户端并发上传图片03 客户端并发登录04 浏览器客户端-自定义服务端05 浏览器客户端-Tomcat服务端 01 TCP上传图片 import java.net ...

  7. 黑马程序员——【Java基础】——网络编程

    ---------- android培训.java培训.期待与您交流! ---------- 一.网络模型概述 网络模型示意图: 说明: (1)数据的传输:在用户端,应用层的数据,经过层层封包,最后到 ...

  8. JAVA基础学习day25--Socket基础二-多线程

    一.上传图片 1.1.示例 /* 上传图片 */ import java.net.*; import java.io.*; import java.util.*; import java.text.* ...

  9. xheditor在线编辑器的使用

    在你所需要在线编辑器的工程目录下,导入xheditor_emot.xheditor_plugins和xheditor_skin.jquery四个文件夹,然后在textarea标签中加入: class= ...

随机推荐

  1. 在Android项目中使用AndroidAnnotations(配置框架,显示Hello World!)

    使用这个框架可以极大的简化在开发Android过程中的代码.提高开发的效率.这里简单说一下配置方式.和使用办法. 项目的地址为:AndroidAnnotations Jar包下载地址:3.0.1 下载 ...

  2. Linux下的C高级编程---学习

    一.进程        一个正在运行的程序称为进程.例如在屏幕上正打开两个终端窗口,则说明同一个终端程序正在做为两个进程而同时执行,而每个终端窗口又都在执行shell,则每个shell又是另外一个进程 ...

  3. stl lower_bound upper_bound binary_search equal_range

    自己按照stl实现了一个:   http://www.cplusplus.com/reference/algorithm/binary_search/ 这里有个注释,如何判断两个元素相同: Two e ...

  4. skyline TerraExplorer fly设置相对路径的方法

    软件环境:TerraExplorer Pro(以下简称TEP)6.5 在TEP中,对于本地(非网络)文件路径,默认都是绝对路径,在移动数据时非常麻烦,以下是本人总结出一些设置相对路径的规则 假设fly ...

  5. POJ2142——The Balance

    刚学习的扩展欧几里得算法,刷个水题 求解  线性不定方程 和  模线性方程 求方程 ax+by=c 或 ax≡c (mod b) 的整数解 1.ax+by=gcd(a,b)的一个整数解: <sp ...

  6. UOJ #142. 【UER #5】万圣节的南瓜灯 并查集

    #142. [UER #5]万圣节的南瓜灯 Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://uoj.ac/problem/142 Descrip ...

  7. C++ BackColor_Dialog

    相关主题 1. 用纯色 设置对话对话框的背景色 2. 用位图 设置对话对话框的背景色 3. 使用Picture Ctrl来设置背景图片         对话框背景色     其他相关 CColorDi ...

  8. delphi 菜单的项目是否可用

    菜单的项目是否可用 TPopupMenu.OnPopup事件 把代码放在这里面判断         // ----------------------------------------------- ...

  9. IOS键盘弹出、隐藏

    IOS键盘 UIKeyboardFrameBeginUserInfoKey:动画开始前键盘的size UIKeyboardFrameEndUserInfoKey:动画结束后键盘的size - (voi ...

  10. ckfinder动态指定上传路径

    默认情况下无法用代码修改config.ascx中的BaseUrl设置,因为其后端代码ConfigFile中并没有提供修改BaseUrl的方法,这里我借用了fckeditor以前的用法:利用sessio ...