富文本ckediter
##<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的更多相关文章
- 富文本编辑器Simditor的简易使用
最近打算自己做一个博客系统,并不打算使用帝国cms或者wordpress之类的做后台管理!自己处于学习阶段也就想把从前台到后台一起谢了.好了,废话不多说了,先来看看富文本编辑器SimDitor,这里是 ...
- 个人网站对xss跨站脚本攻击(重点是富文本编辑器情况)和sql注入攻击的防范
昨天本博客受到了xss跨站脚本注入攻击,3分钟攻陷--其实攻击者进攻的手法很简单,没啥技术含量.只能感叹自己之前竟然完全没防范. 这是数据库里留下的一些记录.最后那人弄了一个无限循环弹出框的脚本,估计 ...
- 图解DevExpress RichEditControl富文本的使用,附源码及官方API
9点半了,刚写到1.2. 该回家了,明天继续写完. 大家还需要什么操作,留言说一下,没有的我明天继续加. 好久没有玩DevExpress了,今天下载了一个玩玩,发现竟然更新到14.2.5了..我去 ...
- jsp富文本图片和数据上传
好记性不如烂笔头,记录一下. 2016的最后一天,以一篇博客结尾迎接新的一年. 此处用的富文本编辑器是wangEditor,一款开源的轻量级的富文本编辑器,这里着重说一下里面的图片上传功能. 服务器端 ...
- UEditor百度富文本编辑器--让编辑器自适应宽度的解决方案
UEditor百度富文本编辑器的initialFrameWidth属性,默认值是1000. 不能够自适应屏幕宽度.如图1: 刚开始的时候,我是直接设置initialFrameWidth=null的.效 ...
- iOS - NSMutableAttributedString富文本的实现
NSMutableAttributedString继承于NSAttributedString(带属性的字符串)能够简单快速实现富文本的效果;不多说直接上效果图和代码,通俗易懂: (一)效果图: (二) ...
- 【代码笔记】iOS-获得富文本设置以后的文字高度
一,效果图. 二,工程图. 三,代码. RootViewController.h #import <UIKit/UIKit.h> @interface RootViewController ...
- PHP Ueditor 富文本编辑器
2016年12月11日 08:46:59 星期日 百度的简版富文本编辑器umeditor很久没更新了 全功能版本的配置项跟umeditor还是有区别的, 这里说下ueditor怎么对接到项目中去, 主 ...
- Java 实现HTML富文本导出至word完美解决方案
一. 问题的提出 最近用java开发一个科技项目信息管理系统,里面有一个根据项目申请书的模板填写项目申报信息的功能,有一个科技项目申请书word导出功能. 已有的实现方式:采用标准的jsp模板输出实现 ...
随机推荐
- maven中在本地maven仓库添加jar包
Maven 手动添加 JAR 包到本地仓库 Maven 确确实实是个好东西,用来管理项目显得很方便,但是如果是通过 Maven 来远程下载 JAR 包的话,我宿舍的带宽是4兆的,4个人共用,有时候用 ...
- 一个简单sql注入的poc
最近在提高自己编程能力,拿一些实用的小工具练下.该脚本为python语言,主要涉及模块urllib,re. 功能:验证CmsEasy5.5爆账号密码 实验用源码:http://pan.baidu.co ...
- Oracle 中的Top写法
由于Oracle不支持select top 语句,所以在Oracle中经常是用order by 跟rownum的组合来实现select top n的查询.简单地说,实现方法如下所示:select 列名 ...
- attr绑定
目的 attr绑定可以设置DOM元素的属性值.例如,当我们需要设置title的值,或者一个img的src值,或者一个超链接的href,使用属性绑定会在model的值发生改变时动态的更新绑定的属性值. ...
- Linux 服务器系统监控脚本 Shell【转】
转自: Linux 服务器系统监控脚本 Shell - 今日头条(www.toutiao.com)http://www.toutiao.com/i6373134402163048961/ 本程序在Ce ...
- selenium+python在Windows的环境搭建
1 python下载安装 python早已安装,不再多说.因为开发使用的python2.7,所以同样使用2.7 2 打开Powershell, 输入python -m pip install sele ...
- HDU 4451 Dressing
HDU 4451 Dressing 题目链接http://acm.split.hdu.edu.cn/showproblem.php?pid=4451 Description Wangpeng has ...
- Q & A
1 使用linux命令或者shell实现:文件words存放英文单词,格式为每行一个英文单词(单词可以重复),统计这个文件中出现次数最多的前10个单词. cat words.txt | sort | ...
- PHP学习过程_Symfony_(1)
从今天开始学习php,感兴趣的同学欢迎一块讨论学习,QQ群新群182983780; 1:配置环境变量 把这php和php5http://pan.baidu.com/s/1pKDq9tT两个文件同时c盘 ...
- kali Rolling安装之后的一些常用配置总结
添加普通用户 useradd -m -G sudo,video,audio,cdrom -s /bin/bash OKing把某个用户添加到组中: sudo usermod -a 用户名 -G 组名 ...