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>