CKEditor粘贴屏幕截图上传图片、使用HttpServlet接收文件实现

CKEditor粘贴屏幕截图上传图片
下载链接:
https://download.csdn.net/download/yebichao/10834320
具体说明:
http://www.qchcloud.cn/system/article/show/58

在这里插入图片描述

public class CKEditorUploadServlet extends HttpServlet {  
    private static String baseDir;// CKEditor的根目录  
    private static boolean debug = false;// 是否debug模式  
    private static boolean enabled = false;// 是否开启CKEditor上传  
    private static Hashtable allowedExtensions;// 允许的上传文件扩展名  
    private static Hashtable deniedExtensions;// 阻止的上传文件扩展名  
    private static SimpleDateFormat dirFormatter;// 目录命名格式:yyyyMM  
    private static SimpleDateFormat fileFormatter;// 文件命名格式:yyyyMMddHHmmssSSS  
    /** 
     * Servlet初始化方法 
     */  
    public void init() throws ServletException {  
        // 从web.xml中读取debug模式  
        debug = (new Boolean(getInitParameter("debug"))).booleanValue();  
        if (debug)  
            System.out.println("\r\n---- SimpleUploaderServlet initialization started ----");  
        // 格式化目录和文件命名方式  
        dirFormatter = new SimpleDateFormat("yyyyMM");  
        fileFormatter = new SimpleDateFormat("yyyyMMddHHmmssSSS");  
        // 从web.xml中获取根目录名称  
        baseDir = getInitParameter("baseDir");  
        // 从web.xml中获取是否可以进行文件上传  
        enabled = (new Boolean(getInitParameter("enabled"))).booleanValue();  
        if (baseDir == null)  
            baseDir = "/UserFiles/";  
        String realBaseDir = getServletContext().getRealPath(baseDir);  
        File baseFile = new File(realBaseDir);  
        if (!baseFile.exists()) {  
            baseFile.mkdirs();  
        }  
        // 实例化允许的扩展名和阻止的扩展名  
        allowedExtensions = new Hashtable(3);  
        deniedExtensions = new Hashtable(3);  
        // 从web.xml中读取配置信息  
        allowedExtensions.put("File",  
        stringToArrayList(getInitParameter("AllowedExtensionsFile")));  
        deniedExtensions.put("File",  
        stringToArrayList(getInitParameter("DeniedExtensionsFile")));  
        allowedExtensions.put("Image",  
    stringToArrayList(getInitParameter("AllowedExtensionsImage")));  
        deniedExtensions.put("Image",           stringToArrayList(getInitParameter("DeniedExtensionsImage")));  
        allowedExtensions.put("Flash",          stringToArrayList(getInitParameter("AllowedExtensionsFlash")));  
        deniedExtensions.put("Flash",           stringToArrayList(getInitParameter("DeniedExtensionsFlash")));  
        if (debug)  
            System.out.println("---- SimpleUploaderServlet initialization completed ----\r\n");  
    }  
    public void doGet(HttpServletRequest request, HttpServletResponse response)  
            throws ServletException, IOException {  
        doPost(request, response);  
    }  

使用HttpServlet接收文件

<%@page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
 
<%
 
	String path = request.getContextPath();
 
	pageContext.setAttribute("path",path);
 
%>
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 
<html xmlns="http://www.w3.org/1999/xhtml">
 
<head>
 
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
 
<script type="text/javascript" src="ckeditor/ckeditor.js"></script>
<script src="http://code.jquery.com/jquery-2.1.4.min.js"></script>
 
<title>CKEditor</title>
 
<style type="text/css">
 
* {
 
	font-family: "宋体";
 
	font-size: 14px
 
}
 
</style>
 
 
 
</head>
 
<body>
 <script type="text/javascript">
            function addNum(){
            var data = CKEDITOR.instances.content.getData();
             window.location.href="${path}/picDao?pic="+data;
            }
          </script>
 
<form id="form1" name="form1" method="post" action="">
<table width="650" height="400" border="0" align="center">
 
 
 
	<tr>
 
		<td>主题:</td>
 
		<td><input name="title" type="text" id="title" size="80" 
 
			maxlength="80" /> </td>
 
	</tr>
 
	<tr>
 
		<td valign="top">内容:</td>
 
		<td><textarea cols="80" id="content" name="content">
 
      </textarea> 
 
	      <script type="text/javascript">

	    	CKEDITOR.replace('content',{filebrowserUploadUrl : '${path}/ckeditor/uploader?Type=File',
 
 
			filebrowserFlashUploadUrl : '${path}/ckeditor/uploader?Type=Flash'
 
	    	});
		</script></td>
 
	</tr>
 
	<tr>
 
		<td></td>
 
		<td><input type="submit" onclick=addNum() name="Submit" value="提交" /> <input
 
			type="reset" name="Reset" value="重置" /></td>
 
	</tr>
 
</table>
 
</form>
 
</body>
 
</html>

在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

码农-004

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值