#kindEditor图片上传-演示Demo
- 需求分析
- 采用kindEditor插件,实现上传图片到服务器。
- 资源准备
kindEditor-4.1.10 下载地址:http://kindeditor.net/down.php
Demo工程搭建
Maven project–>kindEditor-image(war)
pom.xml
<dependencies>
<!-- https://mvnrepository.com/artifact/commons-fileupload/commons-fileupload -->
<dependency>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
<version>1.3.1</version>
</dependency>
<dependency>
<groupId>json.simple</groupId>
<artifactId>json_simple</artifactId>
<version>1.1</version>
</dependency>
</dependencies>
<build>
<plugins>
<!-- java编译插件 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.2</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.2</version>
<configuration>
<!-- 指定端口 -->
<port>9998</port>
<!-- 请求路径 -->
<path>/</path>
</configuration>
</plugin>
</plugins>
</build>
注意:
<dependency>
<groupId>json.simple</groupId>
<artifactId>json_simple</artifactId>
<version>1.1</version>
</dependency>
依赖在中央仓库中没有,需要自己导入到本地仓库,详细看附录
WEB-INF/web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
version="2.5">
</web-app>
- 引入资源
本Demo使用java语言开发,所以就删除了一些没必要的文件。
最好改一下名称 为 kindeditor
###功能实现
- 创建kindEditor.html
1 | 导入富文本编辑器 |
启动服务,访问http://localhost:9998/kindEditor.html,页面展示效果
这时,图片上传是无法实现的,kindeditor单图上传默认使用php做上传
打开/kindeditor/plugins/image/image.js
打开jsp/upload_json.jsp
1 |
|
在webapp下创建文件夹attached.
运行服务,访问 http://localhost:9998/kindEditor.html
Demo效果
#附录: json_simple-1.1.jar导入本地仓库
mvn install:install-file -Dfile=json_simple-1.1.jar -DgroupId=json.simple -DartifactId=json_simple -Dversion=1.1 -Dpackaging=jarr