##<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. 开发中常用的 $.extend 总结

    工作中常见$.extend( ),所以就查了一些它的用法. 一.Jquery的扩展方法原型是: extend(dest, src1, src2, src3...) 它的含义是将src1,src2,sr ...

  2. ACboy needs your help hdu 分组背包问题

    Description ACboy has N courses this term, and he plans to spend at most M days on study.Of course,t ...

  3. ABAP字符串操作 截取字符长度 取位数

    ABAP字符串操作   ABAP對字串的操作方法與其他語言的操作有較大差別,以下是較常用的對字串操作的方法: 1. 字串的連接:CONCATENATEDATA: t1 TYPE c LENGTH 10 ...

  4. 在eclipse中maven web项目部署到tomcat,访问不了

    修改eclipse中tomcat发布路径后,能正常访问

  5. FD.io VPP 技术Neutron VNF vRouter 实现

    在OpenStack Neutron中主要有三种网络设备,路由器(Router),负载均衡器(LB)以及VPN,其中Router作为基础网络设备起到连接子网到子网.内网到外网的作用.不同子网之间的访问 ...

  6. TheFourthJavaText

    在Java语言中,在一个类的内部静态方法是无法直接访问该类的非静态成员的,这一点和C++一致.比如下面的代码: import javax.swing.JOptionPane; public class ...

  7. PHP识别电脑还是手机访问网站

    最近在做phongap的项目,同一套代码,支持pc可以调试,又支持手机app调用接口,如果在pc上不屏掉调用接口js会报错,难以加载 ,所以就在网上找了,这个,不是原创,重在分享. <?php ...

  8. ThreadLocal线程本地变量

    首先说明ThreadLocal存放的值是线程内共享的,线程间互斥的,主要用于线程内共享一些数据,避免通过参数来传递,这样处理后,能够优雅的解决一些实际问题,比如hibernate中的OpenSessi ...

  9. redis加入windows服务自启动

    今天研究了下redis,很简单 下载减压就可以用,但是自启动搞了好久! 直接sc create redis binPath = D:redis/redis-server.exe start = aut ...

  10. Okhttp设置http缓存,在没有网络的情况下加载http缓存里面的内容

    HTTP_CACHE_FILENAME为缓存地址根路径: private final String HTTP_CACHE_FILENAME = "HttpCache"; priva ...