##<link rel='stylesheet' href='/css/index.css' />

<script type="text/javascript" src="/ckeditor/ckeditor.js"></script>

<textarea name="editor1" id="editor1" rows="10" cols="80">

</textarea>

<div style="margin-top:3rem;">

消息标题:<input type="text" id="ctitle" style="width:500px;"/>

<input type="button" id="button1" value="提交" style="height:2.5rem;width:100%;font-size:1.2rem;letter-spacing:3rem;"/>

</div>

<script type="text/javascript">

$(function(){

CKEDITOR.replace( 'editor1', {

filebrowserUploadUrl: '$!{base}/haliluya/uploadimg.html'

});

$("#button1").click(function(){

var editor = CKEDITOR.instances.editor1;

$.ajax({

url : "/haliluya/uploadContent.html",

data : {

'editorData' : editor.getData(),

'ctitle' : $("#ctitle").val()

},

type : "POST",

success : function(result) {

if (result) {

alert("保存成功");

}else{

alert("提交失败");

}

},

error : function(request) {

alert("sorry!");

}

}, "json");

});

});

</script>

package shareAction;

import java.io.File;

import java.io.PrintWriter;

import javax.servlet.ServletContext;

import javax.servlet.http.HttpServletRequest;

import javax.servlet.http.HttpServletResponse;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.stereotype.Controller;

import org.springframework.util.FileCopyUtils;

import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.ResponseBody;

import org.springframework.web.multipart.MultipartFile;

import org.springframework.web.multipart.MultipartHttpServletRequest;

import shareMode.GoodNews;

import shareService.GoodNewsService;

@Controller

@RequestMapping({"/haliluya"})

public class Halelujah

{

@Autowired

private GoodNewsService goodNewsService;

@RequestMapping({"/uploadContent"})

@ResponseBody

public boolean uploadContent(String editorData, String ctitle)

{

boolean ok = true;

GoodNews goodNews = new GoodNews();

goodNews.setContent(editorData);

goodNews.setCtitle(ctitle);

int insert = this.goodNewsService.insertGoodNewsService(goodNews);

if (insert <= 0) {

ok = false;

}

return ok;

}

@RequestMapping({"/uploadimg"})

public void execute(HttpServletResponse response, MultipartHttpServletRequest multipartHttpServletRequest, HttpServletRequest httpServletRequest)

throws Exception

{

MultipartFile file = multipartHttpServletRequest.getFile("upload");

String filename = file.getOriginalFilename();

String imgtype = filename.substring(filename.lastIndexOf("."));

String localhostUrl = "images/contentImg/";

String ctxPath = multipartHttpServletRequest.getSession().getServletContext().getRealPath("/") + localhostUrl;

File dirPath = new File(ctxPath);

if (!dirPath.exists()) {

dirPath.mkdir();

}

filename = String.valueOf(Math.random()) + imgtype;

File uploadFile = new File(ctxPath + filename);

FileCopyUtils.copy(file.getBytes(), uploadFile);

String URL = httpServletRequest.getScheme() + "://" + httpServletRequest.getServerName() + ":" + httpServletRequest.getServerPort() + httpServletRequest.getContextPath() + "/";

String callbackUrl = URL + localhostUrl + filename;

String callback = httpServletRequest.getParameter("CKEditorFuncNum");

PrintWriter out = response.getWriter();

out.println("<script type=\"text/javascript\">");

out.println("window.parent.CKEDITOR.tools.callFunction(" + callback + ",'" + callbackUrl + "','')");

out.println("</script>");

}

@RequestMapping({"/uploadNews"})

public String uploadNews()

{

return "/b/uploadNews";

}

}

富文本ckediter的更多相关文章

  1. 富文本编辑器Simditor的简易使用

    最近打算自己做一个博客系统,并不打算使用帝国cms或者wordpress之类的做后台管理!自己处于学习阶段也就想把从前台到后台一起谢了.好了,废话不多说了,先来看看富文本编辑器SimDitor,这里是 ...

  2. 个人网站对xss跨站脚本攻击(重点是富文本编辑器情况)和sql注入攻击的防范

    昨天本博客受到了xss跨站脚本注入攻击,3分钟攻陷--其实攻击者进攻的手法很简单,没啥技术含量.只能感叹自己之前竟然完全没防范. 这是数据库里留下的一些记录.最后那人弄了一个无限循环弹出框的脚本,估计 ...

  3. 图解DevExpress RichEditControl富文本的使用,附源码及官方API

    9点半了,刚写到1.2.   该回家了,明天继续写完. 大家还需要什么操作,留言说一下,没有的我明天继续加. 好久没有玩DevExpress了,今天下载了一个玩玩,发现竟然更新到14.2.5了..我去 ...

  4. jsp富文本图片和数据上传

    好记性不如烂笔头,记录一下. 2016的最后一天,以一篇博客结尾迎接新的一年. 此处用的富文本编辑器是wangEditor,一款开源的轻量级的富文本编辑器,这里着重说一下里面的图片上传功能. 服务器端 ...

  5. UEditor百度富文本编辑器--让编辑器自适应宽度的解决方案

    UEditor百度富文本编辑器的initialFrameWidth属性,默认值是1000. 不能够自适应屏幕宽度.如图1: 刚开始的时候,我是直接设置initialFrameWidth=null的.效 ...

  6. iOS - NSMutableAttributedString富文本的实现

    NSMutableAttributedString继承于NSAttributedString(带属性的字符串)能够简单快速实现富文本的效果;不多说直接上效果图和代码,通俗易懂: (一)效果图: (二) ...

  7. 【代码笔记】iOS-获得富文本设置以后的文字高度

    一,效果图. 二,工程图. 三,代码. RootViewController.h #import <UIKit/UIKit.h> @interface RootViewController ...

  8. PHP Ueditor 富文本编辑器

    2016年12月11日 08:46:59 星期日 百度的简版富文本编辑器umeditor很久没更新了 全功能版本的配置项跟umeditor还是有区别的, 这里说下ueditor怎么对接到项目中去, 主 ...

  9. Java 实现HTML富文本导出至word完美解决方案

    一. 问题的提出 最近用java开发一个科技项目信息管理系统,里面有一个根据项目申请书的模板填写项目申报信息的功能,有一个科技项目申请书word导出功能. 已有的实现方式:采用标准的jsp模板输出实现 ...

随机推荐

  1. spring mvc 实现文件上传下载

    /** * 文件上传 * @param pictureFile */ @RequestMapping("/reportupload") public ResponseInfo up ...

  2. 服务管理--systemctl命令

    摘要: systemctl 是系统服务管理器命令,它实际上将 service 和 chkconfig 这两个命令组合到一起. 任务 旧指令 新指令 使某服务自动启动 chkconfig --level ...

  3. Selenium+Python之163邮件发送

    今晚写了一个163邮箱登录的脚本,由于不停的访问163登录主页导致直接访问163邮箱主页登录需要输入验证码,因为无法获取到验证码,就这导致直接访问主页登录脚本不可行,为了绕过验证码,现在先访问hao1 ...

  4. Codeforces Round #346 (Div. 2) C Tanya and Toys

    C. Tanya and Toys 题目链接http://codeforces.com/contest/659/problem/C Description In Berland recently a ...

  5. 整理了一份React-Native学习指南

    原文:  http://www.w3ctech.com/topic/909 自己在学习React-Native过程中整理的一份学习指南,包含 教程.开源app和资源网站等,还在不断更新中.欢迎pull ...

  6. maven 3.3.9-bin 和 maven 3.3.9-src 的区别 以及 maven安装包的 .tar.gz后缀与.zip 后缀的区别

    (maven 3.3.9-bin)一个是class的文件包,由java文件编译成的,(maven 3.3.9-src )一个是java文件包即是源码(.tar.gz后缀)是linux的压缩包,(.zi ...

  7. Session小解

    Session特点: 1.Session保存在服务器端,为了获得更高的存取速度,一般把Session保存在内存当中: 2.每个用户都有一个独立的Session,为了避免大量用户访问服务器导致内存溢出, ...

  8. svn 中commit时必须填写备注信息如何设置

    在软件开发团队中总是有人忘记添加备注信息,可以通过下面方式进行设置,从而在commit时强制需要填写备注信息. 在服务端选中需要设置的项目进行设置. 选中项目右键,"所以任务"-& ...

  9. 扣出的图片无法调整大小 photoshop mac版本

  10. python安装pip

    pip类似RedHat里面的yum,安装Python包非常方便.本节详细介绍pip的安装.以及使用方法. 1.pip下载安装 1.1 pip下载 # wget "https://pypi.p ...