Jsf 如何使用';发送服务器';编辑器中的按钮?素面

Jsf 如何使用';发送服务器';编辑器中的按钮?素面,jsf,ckeditor,primefaces-extensions,Jsf,Ckeditor,Primefaces Extensions,我使用以下配置将图像上传到ckeditor.db中: CKEDITOR.editorConfig = function(config) { var contextPath= $(.contextPath).html(); config.filebrowserImageBrowseUrl =contextPath+ '/ckeditor/getimage'; config.filebrowserImageUploadUrl = contextPath+'

我使用以下配置将图像上传到ckeditor.db中:

    CKEDITOR.editorConfig = function(config) {
      var contextPath= $(.contextPath).html();
      config.filebrowserImageBrowseUrl =contextPath+ '/ckeditor/getimage';
      config.filebrowserImageUploadUrl = contextPath+'ckeditor/uploadimage';
      config.filebrowserBrowseUrl = contextPath+'/ckeditor/getimage';
   };
我使用这个servlet上传到db

@SuppressWarnings("unchecked")
public class CKEditorUploadServlet extends HttpServlet {
    private static final long serialVersionUID = -7570633768412575697L;

    private static final Logger LOG = LoggerFactory
            .getLogger(CKEditorUploadServlet.class);
    private static final String ERROR_FILE_UPLOAD = "An error occurred to the file upload process.";
    private static final String ERROR_NO_FILE_UPLOAD = "No file is present for upload process.";
    private static final String ERROR_INVALID_CALLBACK = "Invalid callback.";
    private static final String CKEDITOR_CONTENT_TYPE = "text/html; charset=UTF-8";
    private static final String CKEDITOR_HEADER_NAME = "Cache-Control";
    private static final String CKEDITOR_HEADER_VALUE = "no-cache";

    private static final Pattern PATTERN = Pattern.compile("[\\w\\d]*");

    private String errorMessage = "";

    @Override
    public void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        LOG.info("doGet çalışmaya başladı.");
        doPost(request, response);
    }

    @Override
    public void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        LOG.info("doPost çalışmaya başladı.");
        final ApplicationContext ctx = WebApplicationContextUtils
                .getWebApplicationContext(request.getSession()
                        .getServletContext());
        final UploadedFileService uploadedFileService = (UploadedFileService) ctx
                .getBean("UploadedFileService");

        final UploadedFile uploadedFile = new UploadedFile();
        final PrintWriter out = response.getWriter();

        response.setContentType(CKEDITOR_CONTENT_TYPE);
        response.setHeader(CKEDITOR_HEADER_NAME, CKEDITOR_HEADER_VALUE);

        final FileItemFactory factory = new DiskFileItemFactory();
        final ServletFileUpload upload = new ServletFileUpload(factory);

        try {
            final List items = upload.parseRequest(request);
            if (!items.isEmpty() && items.get(0) != null) {
                uploadedFile.setContent(((DiskFileItem) items.get(0)).get());
                uploadedFile.setContentType(((DiskFileItem) items.get(0))
                        .getContentType());
                uploadedFile.setName(((DiskFileItem) items.get(0)).getName());
                uploadedFileService.saveUploadedFile(uploadedFile);
            } else {
                errorMessage = ERROR_NO_FILE_UPLOAD;
            }

        } catch (final FileUploadException e) {
            errorMessage = ERROR_FILE_UPLOAD;
            LOG.error(errorMessage, e);
        }

        // CKEditorFuncNum Is the location to display when the callback
        String callback = request.getParameter("CKEditorFuncNum");
        // verify if the callback contains only digits and letters in order to
        // avoid vulnerability on parsing parameter
        if (!PATTERN.matcher(callback).matches()) {
            callback = "";
            errorMessage = ERROR_INVALID_CALLBACK;
        }
        final String pathToFile = request.getContextPath()
                + "/ckeditor/getimage?imageId=" + uploadedFile.getId();
        out.println("<script type='text/javascript'>// <![CDATA[window.parent.CKEDITOR.tools.callFunction("
                + callback + ",'" + pathToFile + "','" + errorMessage + "')");
        out.println("// ]]></script>");
        out.flush();
        out.close();
    }
}
}

我将ckeditor图像上载到db.OK。但是当我单击“图像信息”选项卡时,我应该手动写入/(contextPath)/ckeditor/getimage?imageId=(数据库中的图像id)(例如,当将此url:/contextPath/ckeditor/getimage?imageId=1写入到“图像信息”选项卡中的url输入时,一切正常。但我想在向服务器发送自定义图像时自动写入url。我该怎么做?手册对用户不有用。我如何自动设置为url(图像信息选项卡)?提前感谢..

我使用的是primefaces extensions ckeditor。

可能有点晚,但这对我来说很有效……在ckeditor 4.4.6、PF 5.2、PFE 3.2.0中:

private static final String ERROR_INVALID_CALLBACK = "Invalid callback.";
private static final Pattern PATTERN = Pattern.compile("[\\w\\d]*");

    // CKEditorFuncNum Is the location to display when the callback
    String callback = request.getParameter("CKEditorFuncNum");
    // verify if the callback contains only digits and letters in order to
    // avoid vulnerability on parsing parameter
    if (!PATTERN.matcher(callback).matches()) {
        callback = "";
        errorMessage = ERROR_INVALID_CALLBACK;
    }
    String pathToFile = request.getContextPath() + "/ckeditor/getimage?imageId=" + uploadedFile.getId();
    PrintWriter out = response.getWriter();
    out.println("<script type=\"text/javascript\">//<![CDATA[" + "\n\twindow.parent.CKEDITOR.tools.callFunction(" + callback + ",'" + pathToFile + "','" + errorMessage + "')");
    out.println("//]]></script>");
    out.flush();
    out.close();
private静态最终字符串错误\u INVALID\u CALLBACK=“INVALID CALLBACK。”;
private static final Pattern=Pattern.compile(“[\\w\\d]*”);
//CKEditorFuncNum是回调时要显示的位置
字符串回调=request.getParameter(“CKEditorFuncNum”);
//验证回调是否只包含数字和字母,以便
//避免解析参数时出现漏洞
if(!PATTERN.matcher(callback.matches()){
回调=”;
errorMessage=错误\无效\回调;
}
字符串pathToFile=request.getContextPath()+“/ckeditor/getimage?imageId=“+uploadedFile.getId();
PrintWriter out=response.getWriter();
out.println(“/”);
out.flush();
out.close();
private static final String ERROR_INVALID_CALLBACK = "Invalid callback.";
private static final Pattern PATTERN = Pattern.compile("[\\w\\d]*");

    // CKEditorFuncNum Is the location to display when the callback
    String callback = request.getParameter("CKEditorFuncNum");
    // verify if the callback contains only digits and letters in order to
    // avoid vulnerability on parsing parameter
    if (!PATTERN.matcher(callback).matches()) {
        callback = "";
        errorMessage = ERROR_INVALID_CALLBACK;
    }
    String pathToFile = request.getContextPath() + "/ckeditor/getimage?imageId=" + uploadedFile.getId();
    PrintWriter out = response.getWriter();
    out.println("<script type=\"text/javascript\">//<![CDATA[" + "\n\twindow.parent.CKEDITOR.tools.callFunction(" + callback + ",'" + pathToFile + "','" + errorMessage + "')");
    out.println("//]]></script>");
    out.flush();
    out.close();