【问题标题】:Understanding seam filter url-pattern and possible conflicts了解接缝过滤器 url 模式和可能的冲突
【发布时间】:2016-04-25 11:16:17
【问题描述】:

我在 Seam 2.2.2 项目中制作了一个自定义编辑器插件,它可以通过这种方式上传文件:

1) 配置编辑器以加载我的特定 xhtml 上传页面;

2) 在该页面内调用如下方法,并返回一个javascript回调;

public String sendImageToServer()
    {
        HttpServletRequest request = ServletContexts.instance().getRequest();
        try
        {
            List<FileItem> items = new ServletFileUpload(new DiskFileItemFactory()).parseRequest(request);
            processItems(items);//set the file data to specific att
            saveOpenAttachment();//save the file to disk
        }
        //build callback

为此,我必须将其放入 components.xml:

<web:multipart-filter create-temp-files="false"  
                  max-request-size="1024000" url-pattern="*"/> 

属性 create-temp-files 似乎与它的值无关。 但 url-pattern 必须是“”或“/myUploadPage.seam”,任何其他值都会使项目列表返回空。有人知道为什么吗?

这变成了一个问题,因为当我使用适用于这种情况的 url 模式时,我的应用程序中每个带有 enctype="multipart/form-data" 的表单都会停止提交数据。所以我最终导致系统的其他部分崩溃。 有人可以帮我吗?

【问题讨论】:

    标签: xmlhttprequest servlet-filters seam multipartform-data


    【解决方案1】:

    为了解决我的问题,我将解决方案更改为类似于 Seam 多部分过滤器处理请求:

    ServletRequest request = (ServletRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest();
        try
        {
          if (!(request instanceof MultipartRequest))
          {
             request = unwrapMultipartRequest(request);
          }
    
          if (request instanceof MultipartRequest)
          {
             MultipartRequest multipartRequest = (MultipartRequest) request;
    
             String clientId = "upload";
             setFileData(multipartRequest.getFileBytes(clientId));
             setFileContentType(multipartRequest.getFileContentType(clientId));
             setFileName(multipartRequest.getFileName(clientId));
             saveOpenAttachment();
          }
        }
    

    现在我像 Seam 一样处理请求,并且不需要破坏其他类型请求的 web:multipart-filter 配置。

    【讨论】:

      猜你喜欢
      • 2011-12-21
      • 2016-01-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-04-25
      • 1970-01-01
      相关资源
      最近更新 更多