fckeditor2.4.1 相信对于作web的朋友不会很陌生,就是可编辑工具。
1、
fckeditor2.4.1的配置也不难,按照官方的文档一步一步的配置就可以了,理论上是这样的,但是fckeditor2.4.1的Servlet直接用就会出现一些类无法识别的问题,最后看了一下源码进行了一下修改,用来一年多还很稳定
public class ConnectorServlet extends HttpServlet {
private static final long serialVersionUID = -5742008970929377161L;
private static final Logger logger = LoggerFactory
.getLogger(ConnectorServlet.class);
/**
* Initialize the servlet: <code>mkdir</code> <DefaultUserFilesPath>
*/
public void init() throws ServletException, IllegalArgumentException {
String realDefaultUserFilesPath = getServletContext().getRealPath(
ConnectorHandler.getDefaultUserFilesPath());
File defaultUserFilesDir = new File(realDefaultUserFilesPath);
UtilsFile.checkDirAndCreate(defaultUserFilesDir);
logger.info("ConnectorServlet successfully initialized!");
}
/**
* Manage the <code>GET</code> requests (<code>GetFolders</code>,
* <code>GetFoldersAndFiles</code>, <code>CreateFolder</code>).<br/>
*
* The servlet accepts commands sent in the following format:<br/>
* <code>connector?Command=<CommandName>&Type=<ResourceType>&CurrentFolder=<FolderPath></code>
* <p>
* It executes the commands and then returns the result to the client in XML
* format.
* </p>
*/
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
logger.debug("Entering ConnectorServlet#doGet");
response.setCharacterEncoding("UTF-8");
response.setContentType("application/xml; charset=UTF-8");
response.setHeader("Cache-Control", "no-cache");
PrintWriter out = response.getWriter();
String commandStr = request.getParameter("Command");
String typeStr = request.getParameter("Type");
String currentFolderStr = request.getParameter("CurrentFolder");
logger.debug("Parameter Command: {}", commandStr);
logger.debug("Parameter Type: {}", typeStr);
logger.debug("Parameter CurrentFolder: {}", currentFolderStr);
XmlResponse xr;
if (!RequestCycleHandler.isEnabledForFileBrowsing(request))
xr = new XmlResponse(XmlResponse.EN_ERROR,
Messages.NOT_AUTHORIZED_FOR_BROWSING);
else if (!CommandHandler.isValidForGet(commandStr))
xr = new XmlResponse(XmlResponse.EN_ERROR, Messages.INVALID_COMMAND);
else if (typeStr != null && !ResourceTypeHandler.isValid(typeStr))
xr = new XmlResponse(XmlResponse.EN_ERROR, Messages.INVALID_TYPE);
else if (!UtilsFile.isValidPath(currentFolderStr))
xr = new XmlResponse(XmlResponse.EN_ERROR,
Messages.INVALID_CURRENT_FOLDER);
else {
CommandHandler command = CommandHandler.getCommand(commandStr);
ResourceTypeHandler resourceType = ResourceTypeHandler
.getDefaultResourceType(typeStr);
String typePath = UtilsFile.constructServerSidePath(request,
resourceType);
String typeDirPath = getServletContext().getRealPath(typePath);
File typeDir = new File(typeDirPath);
UtilsFile.checkDirAndCreate(typeDir);
File currentDir = new File(typeDir, currentFolderStr);
if (!currentDir.exists())
xr = new XmlResponse(XmlResponse.EN_INVALID_FOLDER_NAME);
else {
xr = new XmlResponse(command, resourceType, currentFolderStr,
UtilsResponse.constructResponseUrl(request,
resourceType, currentFolderStr, true,
ConnectorHandler.isFullUrl()));
if (command.equals(CommandHandler.GET_FOLDERS))
xr.setFolders(currentDir);
else if (command.equals(CommandHandler.GET_FOLDERS_AND_FILES))
xr.setFoldersAndFiles(currentDir);
else if (command.equals(CommandHandler.CREATE_FOLDER)) {
String fileName = request.getParameter("NewFolderName");
fileName = new String(fileName.getBytes("iso8859-1"),"UTF-8");
String newFolderStr = UtilsFile.sanitizeFolderName(fileName);
logger.debug("Parameter NewFolderName: {}", newFolderStr);
File newFolder = new File(currentDir, newFolderStr);
int errorNumber = XmlResponse.EN_UKNOWN;
if (newFolder.exists())
errorNumber = XmlResponse.EN_ALREADY_EXISTS;
else {
try {
errorNumber = (newFolder.mkdir()) ? XmlResponse.EN_OK
: XmlResponse.EN_INVALID_FOLDER_NAME;
} catch (SecurityException e) {
errorNumber = XmlResponse.EN_SECURITY_ERROR;
}
}
xr.setError(errorNumber);
}
}
}
out.print(xr);
out.flush();
out.close();
logger.debug("Exiting ConnectorServlet#doGet");
}
/**
* Manage the <code>POST</code> requests (<code>FileUpload</code>).<br />
*
* The servlet accepts commands sent in the following format:<br />
* <code>connector?Command=<FileUpload>&Type=<ResourceType>&CurrentFolder=<FolderPath></code>
* with the file in the <code>POST</code> body.<br />
* <br>
* It stores an uploaded file (renames a file if another exists with the
* same name) and then returns the JavaScript callback.
*/
@SuppressWarnings("unchecked")
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
logger.debug("Entering Connector#doPost");
response.setCharacterEncoding("UTF-8");
response.setContentType("text/html; charset=UTF-8");
response.setHeader("Cache-Control", "no-cache");
PrintWriter out = response.getWriter();
String commandStr = request.getParameter("Command");
String typeStr = request.getParameter("Type");
String currentFolderStr = request.getParameter("CurrentFolder");
logger.debug("Parameter Command: {}", commandStr);
logger.debug("Parameter Type: {}", typeStr);
logger.debug("Parameter CurrentFolder: {}", currentFolderStr);
UploadResponse ur;
Object[] obj = new Object[4];
// if this is a QuickUpload request, 'commandStr' and 'currentFolderStr'
// are empty
if (Utils.isEmpty(commandStr) && Utils.isEmpty(currentFolderStr)) {
commandStr = "QuickUpload";
currentFolderStr = "/";
}
if (!RequestCycleHandler.isEnabledForFileUpload(request)) {
obj[0] = UploadResponse.SC_SECURITY_ERROR;
obj[1] = null;
obj[2] = null;
obj[3] = Messages.NOT_AUTHORIZED_FOR_UPLOAD;
ur = new UploadResponse(obj);
} else if (!CommandHandler.isValidForPost(commandStr)) {
obj[0] = UploadResponse.SC_ERROR;
obj[1] = null;
obj[2] = null;
obj[3] = Messages.INVALID_COMMAND;
ur = new UploadResponse(obj);
} else if (typeStr != null && !ResourceTypeHandler.isValid(typeStr)) {
obj[0] = UploadResponse.SC_ERROR;
obj[1] = null;
obj[2] = null;
obj[3] = Messages.INVALID_TYPE;
ur = new UploadResponse(obj);
} else if (!UtilsFile.isValidPath(currentFolderStr))
ur = UploadResponse.UR_INVALID_CURRENT_FOLDER;
else {
ResourceTypeHandler resourceType = ResourceTypeHandler
.getDefaultResourceType(typeStr);
String typePath = UtilsFile.constructServerSidePath(request,
resourceType);
String typeDirPath = getServletContext().getRealPath(typePath);
File typeDir = new File(typeDirPath);
UtilsFile.checkDirAndCreate(typeDir);
File currentDir = new File(typeDir, currentFolderStr);
if (!currentDir.exists())
ur = UploadResponse.UR_INVALID_CURRENT_FOLDER;
else {
String newFilename = null;
FileItemFactory factory = new DiskFileItemFactory();
ServletFileUpload upload = new ServletFileUpload(factory);
upload.setHeaderEncoding("UTF-8");
try {
List<FileItem> items = upload.parseRequest(request);
// We upload only one file at the same time
FileItem uplFile = items.get(0);
String rawName = UtilsFile.sanitizeFileName(uplFile
.getName());
String filename = FilenameUtils.getName(rawName);
String baseName = FilenameUtils.removeExtension(filename);
String extension = FilenameUtils.getExtension(filename);
filename = UUID.randomUUID().toString()+"."+extension;
if (!ExtensionsHandler.isAllowed(resourceType, extension)) {
obj[0] = UploadResponse.SC_INVALID_EXTENSION;
obj[1] = null;
obj[2] = null;
obj[3] = null;
ur = new UploadResponse(obj);
}
else if(uplFile.getSize()>10*1024*1024){
obj[0] = 333;
obj[1] = null;
obj[2] = null;
obj[3] = null;
ur = new UploadResponse(obj);
}
else {
// construct an unique file name
File pathToSave = new File(currentDir, filename);
int counter = 1;
while (pathToSave.exists()) {
newFilename = baseName.concat("(").concat(
String.valueOf(counter)).concat(")")
.concat(".").concat(extension);
pathToSave = new File(currentDir, newFilename);
counter++;
}
if (Utils.isEmpty(newFilename)) {
obj[0] = UploadResponse.SC_OK;
obj[1] = UtilsResponse.constructResponseUrl(
request, resourceType, currentFolderStr,
true, ConnectorHandler.isFullUrl()).concat(
filename);
obj[2] = null;
obj[3] = null;
ur = new UploadResponse(obj);
} else {
obj[0] = UploadResponse.SC_RENAMED;
obj[1] = UtilsResponse.constructResponseUrl(
request, resourceType, currentFolderStr,
true, ConnectorHandler.isFullUrl()).concat(
newFilename);
obj[2] = newFilename;
obj[3] = null;
ur = new UploadResponse(obj);
}
// secure image check
if (resourceType.equals(ResourceTypeHandler.IMAGE)
&& ConnectorHandler.isSecureImageUploads()) {
if (UtilsFile.isImage(uplFile.getInputStream()))
uplFile.write(pathToSave);
else {
uplFile.delete();
obj[0] = UploadResponse.SC_INVALID_EXTENSION;
obj[1] = null;
obj[2] = null;
obj[3] = null;
ur = new UploadResponse(obj);
}
} else
uplFile.write(pathToSave);
}
} catch (Exception e) {
obj[0] = UploadResponse.SC_SECURITY_ERROR;
obj[1] = null;
obj[2] = null;
obj[3] = null;
ur = new UploadResponse(obj);
}
}
}
out.print(ur);
out.flush();
out.close();
logger.debug("Exiting Connector#doPost");
}
}
2、
fckeditor.properties 放到classpath下面 内容:connector.userActionImpl=net.fckeditor.requestcycle.impl.UserActionImpl
3、web.xml的配置:<servlet>
<servlet-name>Connector</servlet-name>
<servlet-class>com.lustersoft.ssp.fckeditor.ConnectorServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Connector</servlet-name>
<url-pattern>/fckeditor/editor/filemanager/connectors/*</url-pattern>
</servlet-mapping>
主要的配置文件我上传,希望对有需求的朋友带来帮助
分享到:
相关推荐
**FCKeditor2.4.1版本(JAVA版)配置详解** FCKeditor是一款非常流行的开源HTML文本编辑器,主要用于网页中的内容编辑。在2.4.1版本中,它为JAVA开发人员提供了丰富的功能,使得在Web应用中集成富文本编辑变得简单易...
包括fckeditor2.6.4+fckeditor-java-2.4.1配置所需资源包及fckeditor-java-2.4.1源码和配置说明文档。 配置中解决了中文乱码,并为上传文件自动创建日期文件夹。
"Fckeditor-java-2.4.1-bin"是一个用于Java平台的富文本编辑器软件包,主要功能是为Web应用程序提供一个强大的在线文本编辑工具。FCKeditor是一款开源的JavaScript库,它允许用户在网页上创建类似桌面应用的文本编辑...
集成FCKeditor到Java Web应用中,通常需要在Web应用的`web.xml`配置文件中注册`FCKEditorServlet`,然后在客户端页面上嵌入JavaScript代码来调用服务器端组件。 6. **性能优化** 通过对源码的优化,可以提高...
而"fckeditor-java-2.4.1"可能包含了编译后的Java类库文件、示例程序、配置文件等,供开发者直接引用和学习。 在实际应用中,使用FCKeditor-java-2.4.1,开发者需要按照官方文档或提供的示例进行配置,包括设置编辑...
"fckeditor-java-2.4.1-src"是FCKeditor的源代码版本,版本号为2.4.1,这个压缩包包含了开发和定制FCKeditor所需的所有源文件。通过这个源代码,开发者可以深入理解编辑器的工作原理,同时也方便了对编辑器进行功能...
1. 部署`fckeditor-java-demo-2.4.1.war`:将此WAR文件部署到Java应用服务器,按照服务器的配置说明进行操作,一般只需将其复制到服务器的webapps目录下,服务器会自动进行解压和启动。 2. 引入FCKeditor库:在Java...
在使用FCKeditor-java-core-2.4.1时,开发者需要将其引入到他们的Java Web项目中,配置相关的参数,如编辑器的宽度、高度、工具栏布局等,并在需要的地方调用API来初始化和使用编辑器。同时,为了保证安全性和用户...
在实际应用中,FCKeditor的配置主要通过JavaScript实现,而jar包则负责后端处理,如验证用户提交的HTML内容,过滤非法标签,或者在服务器端生成HTML以保存到数据库。这种前后端分离的模式有助于提高应用的安全性和可...
这个压缩包"**fckeditor java Web开发完全组合包,及配置过程.rar**"包含了在Java Web环境下集成和使用FCKeditor所需的所有组件和步骤说明,由作者亲身体验并整理。 1. **FCKeditor 2.4.1**: 这是FCKeditor的一个...
4. **易于集成**:FCKeditor与JSP的集成非常简单,只需在服务器端配置并嵌入到网页中,即可实现在线编辑功能。开发者可以通过API调用来扩展或定制编辑器的行为。 5. **安全性**:为了防止XSS(跨站脚本攻击)和其他...
- 配置 `fckeditor-java-2.4.1` 目录中的依赖库: - **必须包含的 JAR 包**:`commons-fileupload-1.2.1.jar`, `commons-io-1.3.2.jar`, `fckeditor-java-core-2.4.1.jar`, `slf4j-api-1.5.6.jar`, `slf4j-simple-...
"Fckeditor-java-demo-2.4.1.war" 是一个基于Java的Web应用程序示例,主要用于展示FCKeditor的功能。FCKeditor是一个流行的开源富文本编辑器,它允许用户在网页上创建和编辑内容,类似于Microsoft Word的功能。这个...
【FCKeditor配置详解】 FCKeditor是一款流行的开源富文本编辑器,常用于网页内容的编辑和管理。本文将深入探讨如何将FCKeditor 2.4版本集成到SSH(Struts2、Hibernate、Spring)框架中,并解决可能出现的问题。 **...
《深入解析FCKeditor2.6.3b与Java整合在JSP中的应用》 FCKeditor是一款广受欢迎的开源富文本编辑器,其2.6.3b版本以其强大的功能和良好的用户界面赢得了开发者们的青睐。这款编辑器支持多种编程语言,包括Java,...
在本文中,我们将深入探讨如何在Java环境中集成和配置FCKeditor,这是一个强大的富文本编辑器,常用于网站内容管理系统的文本编辑功能。FCKeditor提供了丰富的文本格式化选项,如字体、颜色、图片和多媒体文件的插入...