kindEditor文本编辑器中上传本地图片的功能官方文档中已经提供了几种语言。
1.↓↓↓这个插件里面需要手动配置的两个重要的jsp文件。
在upload_json.jsp中
<%@ page language=
"java"
contentType=
"text/html; charset=UTF-8"
pageEncoding=
"UTF-8"
%><%@ page
import
=
"java.util.*,java.io.*"
%><%@ page
import
=
"java.text.SimpleDateFormat"
%><%@ page
import
=
"org.json.simple.*"
%><%
/** * KindEditor JSP */
//根目录路径,可以指定绝对路径,比如 /var/www/attached/
String rootPath = pageContext.getServletContext().getRealPath(
"/"
) +
"attached/"
;
//根目录URL,可以指定绝对路径,比如 http://www.yoursite.com/attached/
String rootUrl = request.getContextPath() +
"/attached/"
;
//图片扩展名
String[] fileTypes =
new
String[]{
"gif"
,
"jpg"
,
"jpeg"
,
"png"
,
"bmp"
};String dirName = request.getParameter(
"dir"
);
if
(dirName !=
null
) {
if
(!Arrays.<String>asList(
new
String[]{
"image"
,
"flash"
,
"media"
,
"file"
}).contains(dirName)){ out.println(
"Invalid Directory name."
);
return
; } rootPath += dirName +
"/"
; rootUrl += dirName +
"/"
; File saveDirFile =
new
File(rootPath);
if
(!saveDirFile.exists()) { saveDirFile.mkdirs(); }}
如果是非maven项目
需要你在WebRoot根目录下创建图片上传路径(必须创建不然会报目录不存在的错误-KindEditor的本地上传是把图片放到服务器里)。
如果是maven项目
在maven项目中,则需要在webapp下创建文件夹attached
如果没有创建则会提示目录不存在
kindEditor中采用的是
<%@ page
import
=
"org.json.simple.*"
%>
一般情况是需要自己下载json_simple.jar
这里也可以使用其他的jar,举个栗子:fastJson ...
其他的基本按照官网的文档就可以了!