##<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. UITableView优化方案

    1.UITableView的简单认识 > UITableView最核心的思想就是UITableViewCell的重用机制.简单的理解就是:UITableView只会创建一屏幕(或一屏幕多一点)的 ...

  2. centos7安装mariadb后无法启动的问题

    MariaDB数据库管理系统是MySQL的一个分支,主要由开源社区在维护,采用GPL授权许可.开发这个分支的原因之一是:甲骨文公司收购了MySQL后,有将MySQL闭源的潜在风险,因此社区采用分支的方 ...

  3. python 主机宝

    需求:开发一个主机批量管理系统,要求按saltstack方式执行命令 #!/usr/bin/env python3. # -*- coding:utf8 -*- import os,sys,pickl ...

  4. 《HTML5与CSS3权威指南》读书笔记(上册)—HTML5篇

    豆瓣上的评分少且评价不太好,阅读当中发现几处刊物上的小问题,不过线下口碑貌似不错,基本上人手一本 上册五百多页,主讲H5,分为标签,本地存储,离线应用程序,新的API,获取地理位置信息标签包含表单,C ...

  5. ajax jsonp 跨域请求

    $.ajax({ type:"get", url: "http://localhost/test/a.php", dataType: "jsonp&q ...

  6. 批量修改安卓apk包名

    1.准备工作 1.1 反编译工具apktool下载 1.2 java, android SDK安装 1.2 python安装 2.反编译现有包 apktool.bat d test.apk 3. 直接 ...

  7. git clone出现SSL错误

    在学习git的时候,发现不能使用git clone从github.com下载,报了个ssl错误. Cloning into cancan... error: SSL certificate probl ...

  8. JavaScript eval() 为什么使用eval()是一个坏主意 什么时候可以使用eval()

    ---------------------------------------------------------------------------------------------------- ...

  9. SPA UI-router

    ------------------------------------------------------------------------------------ SPA SPA(单页面应用): ...

  10. 记一次-angular-数字格式化

    一个收费功能模块,需要做数据验证. input标签的ng-model的数据格式化 <input type="number" class="form-control& ...