1. 程式人生 > >fckeditor2.6.6 java上傳圖片到絕對路徑的配置

fckeditor2.6.6 java上傳圖片到絕對路徑的配置

改絕對路徑不需要修改原始碼。增加一些簡單的配置就可以了。可以回顯。另外要設定tomcat的server.xml,加一個硬碟對映。

fckeditor 2.6.6

我的是maven工程。

1:拷貝fckeditor資料夾到webapp/js下面

2:修改fckeditor/fckeditor.js裡面的FCKeditor.BasePath = '/js/fckeditor/' ;

3:web.xml裡面加入

<servlet>
   <servlet-name>Connector</servlet-name>
   <servlet-class>
    net.fckeditor.connector.ConnectorServlet
   </servlet-class>
   <load-on-startup>1</load-on-startup>
  </servlet>
  <servlet-mapping>
   <servlet-name>Connector</servlet-name>
   <url-pattern>
    /js/fckeditor/editor/filemanager/connectors/*
   </url-pattern>
  </servlet-mapping>

4:src/main/resources下面新建fckeditor.properties,寫入

connector.userActionImpl=net.fckeditor.requestcycle.impl.EnabledUserAction

#connector.impl = net.fckeditor.connector.impl.LocalConnector
#connector.userPathBuilderImpl = com.hb.FilePathBuilder


#################################################################
#connector.impl=com.hb.ContextConnector
#connector.userPathBuilderImpl = com.hb.ContextPathBuilder


connector.userFilesAbsolutePath = E://image
connector.userFilesPath = http://localhost:9080/image
  
connector.userPathBuilderImpl = net.fckeditor.requestcycle.impl.ServerRootPathBuilder
connector.impl = net.fckeditor.connector.impl.LocalConnector

5:加入依賴。pom裡面加入

<dependency>
			<groupId>javax.servlet</groupId>
			<artifactId>servlet-api</artifactId>
			<version>2.5</version>
			<scope>provided</scope>
		</dependency>
		<dependency>
			<groupId>javax.servlet.jsp</groupId>
			<artifactId>jsp-api</artifactId>
			<version>2.1</version>
			<scope>provided</scope>
		</dependency>
		<dependency>
			<groupId>javax.servlet</groupId>
			<artifactId>jstl</artifactId>
			<version>1.2</version>
			<scope>provided</scope>
		</dependency>
		
		<dependency>
			<groupId>net.fckeditor</groupId>
			<artifactId>java-core</artifactId>
			<version>2.6</version>
		</dependency>
		<dependency>
			<groupId>org.devlib.schmidt</groupId>
			<artifactId>imageinfo</artifactId>
			<version>1.9</version>
		</dependency>
		<dependency>
			<groupId>org.slf4j</groupId>
			<artifactId>slf4j-simple</artifactId>
			<version>1.5.8</version>
		</dependency>

6:server.xml配置context,加入

<Context path="/image" docBase="E:\image" reloadable="true" debug="0"/>

7:jsp檔案

<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.fckeditor.net" prefix="FCK"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>FckEditor測試</title>
</head>
<body style="text-align: center;">
<div style="text-align: center;width: 600pt">
<h2>FckEditor測試</h2>
<hr>
<form action="ShowData.jsp" method="post">
  <FCK:editor basePath="/js/fckeditor/" instanceName="test" height="400pt">
   <jsp:attribute name="value">www.sunchis.com</jsp:attribute>
  </FCK:editor>     
   <input type="submit" value="提交"/>
   <input type="reset" value="重置"/>
   </form>
</div>
</body>
</html>

如果設定了fckeditor的基本路徑,比如這裡房子js下面,要修改的地方有jsp裡面的basePath、web.xml、fckeditor.xml

如果直接放在webapp下面,這些檔案都不需要修改


You are not authorized to browse/list files and/or folders

我開始沒有使用pom配置jar包,後來fckeditor.properties裡面類名後面多了空格,報出這個錯誤。實際上是因為fck預設不提供上傳圖片的許可權,必須宣告connector.userActionImpl=net.fckeditor.requestcycle.impl.EnabledUserAction

而web.xml配置fck路徑錯誤的話,會報出The server didn't reply with a proper XML data. Please check your configuration.