`
chc9chc
  • 浏览: 5108 次
  • 性别: Icon_minigender_1
  • 来自: 北京
最近访客 更多访客>>
社区版块
存档分类
最新评论

appfuse2.0.2(Struts Basic)整合FCKEditor2.4

阅读更多
appfuse2.0.2(SSH)使用了Struts2.0+Spring2.5+hibernate3.2 还有sitemesh2.2,其中Struts2和SiteMesh会与FckEditor发生冲突,上网搜了很多资料,整理如下:
一.将FckEditor目录考入Web应用下,将带"_"的和多余的语言包清除掉,删除/_documentation.html,_whatsnew.html,fckeditor.afp,fckeditor.asp,fckeditor.cfc,fckeditor.cfm,fckeditor.lasso,fckeditor.php,fckeditor.pl,fckeditor.py只剩下fckconfig.js,fckeditor.js,fckstyles.xml,fcktemplates.xml,htaccess.txt,license.txt删掉/editor/filemanager/browser/default/connectors、/editor/filemanager/upload、语言包/editor/lang中只留下en.js、zh-cn.js
二.配置web.xml
增加
<servlet>
		<servlet-name>Connector</servlet-name>
		<servlet-class>
			com.mumu.app.util.ConnectorServlet
		</servlet-class>
		<load-on-startup>1</load-on-startup>
	</servlet>

	<servlet-mapping>
		<servlet-name>Connector</servlet-name>
		<!-- Do not wrap this line otherwise Glassfish will fail to load this file -->
		<url-pattern>/fckeditor/editor/filemanager/connectors/*</url-pattern>
	</servlet-mapping>

其中com.mumu.app.util.ConnectorServlet是从fck源代码中考出重写的,解决上传中文文件失败的错误。
以下是我的ConnectorServlet代码:
/*
 * FCKeditor - The text editor for Internet - http://www.fckeditor.net
 * Copyright (C) 2003-2008 Frederico Caldeira Knabben
 * 
 * == BEGIN LICENSE ==
 * 
 * Licensed under the terms of any of the following licenses at your
 * choice:
 * 
 *  - GNU General Public License Version 2 or later (the "GPL")
 *    http://www.gnu.org/licenses/gpl.html
 * 
 *  - GNU Lesser General Public License Version 2.1 or later (the "LGPL")
 *    http://www.gnu.org/licenses/lgpl.html
 * 
 *  - Mozilla Public License Version 1.1 or later (the "MPL")
 *    http://www.mozilla.org/MPL/MPL-1.1.html
 * 
 * == END LICENSE ==
 */
package com.mumu.app.util;

import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;
import java.util.UUID;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.fckeditor.handlers.CommandHandler;
import net.fckeditor.handlers.ConnectorHandler;
import net.fckeditor.handlers.ExtensionsHandler;
import net.fckeditor.handlers.RequestCycleHandler;
import net.fckeditor.handlers.ResourceTypeHandler;
import net.fckeditor.response.UploadResponse;
import net.fckeditor.response.XmlResponse;
import net.fckeditor.tool.Utils;
import net.fckeditor.tool.UtilsFile;
import net.fckeditor.tool.UtilsResponse;
import net.fckeditor.connector.Messages;

import org.apache.commons.fileupload.FileItem;
import org.apache.commons.fileupload.FileItemFactory;
import org.apache.commons.fileupload.disk.DiskFileItemFactory;
import org.apache.commons.fileupload.servlet.ServletFileUpload;
import org.apache.commons.io.FilenameUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * Servlet to upload and browse files.<br />
 * <p/>
 * This servlet accepts 4 commands which interact with the server-side
 * filesystem.<br />
 * The allowed commands are:
 * <ul>
 * <li><code>GetFolders</code>: Retrieves a list of folders in the current
 * folder</li>
 * <li><code>GetFoldersAndFiles</code>: Retrives a list of files and folders
 * in the current folder</li>
 * <li><code>CreateFolder</code>: Creates a new folder in the current folder</li>
 * <li><code>FileUpload</code>: Stores an uploaded file into the current
 * folder. (must be sent with POST)</li>
 * </ul>
 *
 * @version $Id: ConnectorServlet.java 2101 2008-06-22 22:00:48Z mosipov $
 */
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> &lt;DefaultUserFilesPath&gt;
     */
    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/>
     * <p/>
     * The servlet accepts commands sent in the following format:<br/>
     * <code>connector?Command=&lt;CommandName&gt;&Type=&lt;ResourceType&gt;&CurrentFolder=&lt;FolderPath&gt;</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 tempStr = request.getParameter("NewFolderName");
                    tempStr = new String(tempStr.getBytes("iso8859-1"), "utf-8");
                    String newFolderStr = UtilsFile.sanitizeFolderName(tempStr);
                    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 />
     * <p/>
     * The servlet accepts commands sent in the following format:<br />
     * <code>connector?Command=&lt;FileUpload&gt;&Type=&lt;ResourceType&gt;&CurrentFolder=&lt;FolderPath&gt;</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;

        // 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))
            ur = new UploadResponse(UploadResponse.SC_SECURITY_ERROR, null, null, Messages.NOT_AUTHORIZED_FOR_UPLOAD);
        else if (!CommandHandler.isValidForPost(commandStr))
            ur = new UploadResponse(UploadResponse.SC_ERROR, null, null, Messages.INVALID_COMMAND);
        else if (typeStr != null && !ResourceTypeHandler.isValid(typeStr))
            ur = new UploadResponse(UploadResponse.SC_ERROR, null, null, Messages.INVALID_TYPE);
        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);

                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))
                        ur = new UploadResponse(UploadResponse.SC_INVALID_EXTENSION);
                    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))
                            ur = new UploadResponse(UploadResponse.SC_OK, UtilsResponse
                                    .constructResponseUrl(request, resourceType, currentFolderStr,
                                            true, ConnectorHandler.isFullUrl()).concat(filename));
                        else
                            ur = new UploadResponse(UploadResponse.SC_RENAMED,
                                    UtilsResponse.constructResponseUrl(request, resourceType,
                                            currentFolderStr, true, ConnectorHandler.isFullUrl())
                                            .concat(newFilename), newFilename);

                        // secure image check
                        if (resourceType.equals(ResourceTypeHandler.IMAGE)
                                && ConnectorHandler.isSecureImageUploads()) {
                            if (UtilsFile.isImage(uplFile.getInputStream()))
                                uplFile.write(pathToSave);
                            else {
                                uplFile.delete();
                                ur = new UploadResponse(UploadResponse.SC_INVALID_EXTENSION);
                            }
                        } else
                            uplFile.write(pathToSave);

                    }
                } catch (Exception e) {
                    ur = new UploadResponse(UploadResponse.SC_SECURITY_ERROR);
                }
            }
        }

        out.print(ur);
        out.flush();
        out.close();

		logger.debug("Exiting Connector#doPost");
	}

}

三.将web.xml中的"<filter-mapping>
        <filter-name>struts</filter-name>
        <url-pattern>/*</url-pattern>
        <dispatcher>REQUEST</dispatcher>
        <dispatcher>FORWARD</dispatcher>
    </filter-mapping>"
改为
"<filter-mapping>
        <filter-name>struts</filter-name>
        <url-pattern>*.action</url-pattern>
        <dispatcher>REQUEST</dispatcher>
        <dispatcher>FORWARD</dispatcher>
    </filter-mapping>"
其中“*.action”是你的Struts应用后缀,在Struts.xml的“<constant name="struts.action.extension" value="action"/>”中配置.
四.将FCKeditor.tld拷入工程的WEB-INF下.
五.在资源文件中增加两个配置文件,
1.增加fckeditor.properties,内容为
connector.userActionImpl=net.fckeditor.requestcycle.impl.UserActionImpl

2.增加struts.properties内容为
struts.multipart.saveDir = /tmp

至此fck已经可以使用,但当你使用时,还会有另外一个问题,在FireFox或google的浏览器中没有问题,在IE下fck的编辑框无法显示,在左下角状态栏中会出现FCKEditor for internet Explorer 5.5x的字样,经实验是因为<FCK:editor>的上面有形如"<s:textfield/>"的标签,如
<s:textfield key="news.newsAuthor" required="false" maxlength="30" cssClass="text medium"/>
    <s:textfield key="news.newsDate" required="false" maxlength="30" cssClass="text medium"/>
    <s:textfield key="news.newsFrom" required="false" maxlength="30" cssClass="text medium"/>
    <s:textfield key="news.newsTitle" required="false" maxlength="50" cssClass="text medium"/>
    <FCK:editor instanceName="news.newsContent" height="400pt" toolbarSet="${param.toolbar}">
        <jsp:attribute name="value">${news.newsContent}</jsp:attribute>
    </FCK:editor>
IE下就会无法显示,套入表格可解决该问题,是什么原因我还不知道,例如:
 <table width="100%"><tr><td>
    <s:textfield key="news.newsAuthor" required="false" maxlength="30" cssClass="text medium"/>
    <s:textfield key="news.newsDate" required="false" maxlength="30" cssClass="text medium"/>
    <s:textfield key="news.newsFrom" required="false" maxlength="30" cssClass="text medium"/>
    <s:textfield key="news.newsTitle" required="false" maxlength="50" cssClass="text medium"/>
    </td></tr>
    <tr><td>
    <s:textfield key="news.newsAuthor" required="false" maxlength="30" cssClass="text medium"/>
    <s:textfield key="news.newsDate" required="false" maxlength="30" cssClass="text medium"/>
    <s:textfield key="news.newsFrom" required="false" maxlength="30" cssClass="text medium"/>
    <s:textfield key="news.newsTitle" required="false" maxlength="50" cssClass="text medium"/>
    <FCK:editor instanceName="news.newsContent" height="400pt" toolbarSet="${param.toolbar}">
        <jsp:attribute name="value">${news.newsContent}</jsp:attribute>
    </FCK:editor></td></tr></table>
1
0
分享到:
评论

相关推荐

    appfuse2.0.2 Struts2 hibernate Spring 构建的基于SQLServer2005 的ssh2项目的过程全记录

    appfuse2.0.2 Struts2 hibernate Spring 构建的基于SQLServer2005 的ssh2项目的过程全记录 网上很多帖子介绍appfuse2构建过程的,但是基于SQLServer2005的没有,顶多一笔带过,另外对于期间出现的各种问题也没有个说明,...

    appfuse 2.0.2PDF格式文档

    标题:AppFuse 2.0.2 - 快速启动Web应用开发的开源框架 描述:AppFuse 2.0.2文档,PDF格式,详细介绍了AppFuse的应用、特性和如何利用它加速Web应用的开发过程。 AppFuse是一款用于“快速启动”Web应用开发的开源...

    appfuse 2.0.2文档 pdf

    标题提及的是"appfuse 2.0.2文档",这表明我们要探讨的是AppFuse项目的一个特定版本,即2.0.2的文档内容。AppFuse是一个开源项目,它提供了一个快速开发Java Web应用程序的基础框架。这个版本的文档很可能是关于如何...

    APPFUSE2.0中加入FCKeditor

    1. **APPFuse 2.0**:APPFuse是一个基于Maven的开源项目,它提供了多种Java Web应用框架的起点,如Struts、Spring MVC、JSF等。2.0版本可能包含了一些对早期版本的改进和更新,比如支持更多的框架、优化的模板或更好...

    Appfuse1.9至2.0.2

    主要是自己从网络上搜集的一些关于appfuse1.8.2-2.0.2的一些相关资料,间或有点自己试验的记录,还有点maven和quartz的东东,之前我主要是用1.8.2构建项目,感觉还不错,希望对想学习appfuse的人有些帮助.

    appfuse/display/strutsMenu

    最后,结合提供的文档和PPT,实践配置AppFuse环境,并将DisplayTag和StrutsMenu整合到项目中。 在实际开发过程中,掌握这些技术可以显著提高开发效率,减少代码重复,并使应用的界面更加用户友好。同时,理解它们的...

    appfuse-tutorial-struts-1.6.zip_appfuse

    这个"appfuse-tutorial-struts-1.6.zip"文件是一个基于Struts 1.6的AppFuse教程,用于指导开发者如何构建一个企业级的人员管理系统。Struts是Apache软件基金会下的一个开源框架,专门用于构建基于MVC(Model-View-...

    SSH学习及开发框架-appfuse

    有struts2+hibernate+spring的整合 springmvc+hibernate+spring的整合 多模块,但模块都有 学习开发参考使用非常方便 可以到官方下载最新版的,我只是把自己下载的打包整理一下 注意哈,都是基于maven的项目哈

    Struts2、Spring和Hibernate应用实例.

    在本文中,笔者将Struts2.0.6、Spring2.0.6和Hibernate3.1进行整合,希望通过这样的整合示例,让读者了解这些框架各自的特点,以便于在自己的项目中,根据实际情况,尽快的过渡到Struts2的时代。本文的内容基于...

    appfuse

    在AppFuse 2.0时代,它主要支持Struts或 Tapestry 框架,而非现代的Spring Boot。由于描述中提到“没有jar包”,这可能意味着下载的实例源码不包含运行所需的所有依赖库,因此需要开发者自行解决这个问题。 首先,...

    appfuse 学习笔记

    ### Appfuse 学习笔记 #### 一、Appfuse 简介 Appfuse 是一个开源框架,旨在帮助开发者高效地构建企业级应用。通过提供一套完善的架构模板、最佳实践和技术栈组合,使得开发者能够专注于业务逻辑的实现,而不是...

    Appfuse2搭建文档

    Appfuse2是一款开源的Web应用程序框架,它集成了多种流行的技术,如Struts、Hibernate、Spring和JPA,旨在简化Java应用的开发过程。本文档将详细介绍如何利用Appfuse2来构建一个基于Oracle数据库的项目。 首先,让...

    APPFUSE工具研究.doc

    AppFuse 2.0还更新了技术栈,支持JDK 5、注解、JSP 2.0和Servlet 2.4,同时提供了对Eclipse、IntelliJ IDEA和NetBeans等IDE的良好支持,以提高开发效率。 此外,AppFuse 2.0集成了多种开源项目,如: 1. **Struts ...

    appfuse学习笔记(一)安装部署

    替换 `&lt;选择的模板&gt;` 为下载的模板名称,如 `appfuse-basic`,`appfuse-minimal` 等,`&lt;对应版本&gt;` 是你下载的 AppFuse 版本号。 **4. 编译与运行** 进入新创建的项目目录,使用 Maven 编译并运行项目: ``` cd my...

    建立项目原型骨架的步骤(最新版本appfuse)appfuse2.1.0-M2

    `mvn archetype:generate -B -DarchetypeGroupId=org.appfuse.archetypes -DarchetypeArtifactId=appfuse-basic-struts-archetype -DarchetypeVersion=2.1.0-M2 -DgroupId=cn.xue.app -DartifactId=xueAppFuse` ...

    Using Struts 2 - AppFuse 2 - Confluence(1).pdf

    ### 使用Struts 2与AppFuse 2:深入解析与实战指南 #### 一、Struts 2简介 Struts 2(前身为WebWork)是一款以简洁为设计理念的Web框架,它基于XWork构建,XWork是一个通用的命令模式框架。尽管XWork拥有自己的...

Global site tag (gtag.js) - Google Analytics