zoukankan      html  css  js  c++  java
  • 富文本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";

    }

    }

  • 相关阅读:
    Android 跳转到系统应用管理
    Android权限管理PermissionsDispatcher2.3.2使用+原生6.0权限使用
    Android权限管理PermissionsDispatcher2.3.2使用+原生6.0权限使用
    Android 6.0 Permission权限与安全机制
    Windows下Mongodb安装及配置
    mongo 3.0 备份和还原数据库 ,及too many positional arguments错误
    maven 将jar 下载到工程当前目录下
    MyBatis两张表字段名相同产生的问题
    svn报错can only be performed on a version resource [at this time].
    angular之interceptors拦截器
  • 原文地址:https://www.cnblogs.com/thankyouGod/p/6022278.html
Copyright © 2011-2022 走看看