• 富文本


    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="500px;"/>

    <input type="button" id="button1" value="提交" style="height:2.5rem;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";

    }

    }

  • 相关阅读:
    docker入门——centos安装
    NET应用——你的数据安全有必要升级
    mysql事件机制——定时任务
    是时候升级你的Js工具了-分页【基于JQ】
    优美库图片系统
    爬虫之蜂鸟网图片爬取
    壁纸提取
    CSDN刷阅读数
    tkinter基础-输入框、文本框
    数据结构与算法之选择排序
  • 原文地址:https://www.cnblogs.com/thankyouGod/p/6022314.html
Copyright © 2020-2023  润新知