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=" target="_blank" rel="external nofollow" +data;
}
</script>
<form id="form1" name="form1" method="post" action="">
<table width="650" height="400" 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>