JSF 2.2 - 文件上传不与阿贾克斯的工作。形态似乎有不正确的enctype(只能通过AJAX) [英] JSF 2.2 - fileupload does not work with Ajax. Form appears to have incorrect enctype (only via AJAX)

查看:163
本文介绍了JSF 2.2 - 文件上传不与阿贾克斯的工作。形态似乎有不正确的enctype(只能通过AJAX)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

试图执行JSF 2.2例子,我有以下的code:

Trying to implement the JSF 2.2 example I have the following code:

<h:form prependId="false" enctype="multipart/form-data">

    <!-- Now it's the AJAX file upload component -->
    <h:inputFile id="fileUpload" value="#{someBean.file}" >
        <f:ajax />
    </h:inputFile>

    <h:commandButton value="Upload" />
</h:form>

据一些JSF 2.2,这应该工作,但在我的情况下,它是给我下面的错误:

According to some JSF 2.2 this should work but in my case it is giving me the following error:

该请求不包含的multipart / form-data的或/混合   流,内容类型头球   应用程序/ x-WWW的形式urlen codeD;字符集= UTF-8

the request doesn't contain a multipart/form-data or multipart/mixed stream, content type header is application/x-www-form-urlencoded;charset=UTF-8

展望请求我虽然正确设置我的表单的enctype,部分要求提交:

Looking into the request although I have set my form enctype correctly, the partial request submits:

内容类型:应用程序/ x-WWW的形式urlen codeD;字符集= UTF-8   面请求:部分/ AJAX

Content-type:application/x-www-form-urlencoded;charset=UTF-8 Faces-Request:partial/ajax

需要注意的是web.xml中也被修改为:

Note that web.xml also was modified to:

<servlet>
    <servlet-name>Faces Servlet</servlet-name>
    <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
    <multipart-config>
        <location>c:\dotmp</location>
        <max-file-size>20848820</max-file-size>
        <max-request-size>418018841</max-request-size>
        <file-size-threshold>1048576</file-size-threshold>
    </multipart-config>
</servlet>

我使用Mojarra 2.2.0-M15,但试图与早期版本也是如此。有谁知道关于这个问题,我认为是一个错误?任何有用的信息。

I am using Mojarra 2.2.0-m15 but tried this with earlier versions as well. Does anyone know any useful info about this issue, which I assume is a bug?

推荐答案

我不知道,因为我还没有看到此之前发生了什么事情。用今天的Mojarra 2.2.1快照,你可以从<下载时,下面的结构为我工作href="https://maven.java.net/service/local/artifact/maven/redirect?r=snapshots&g=org.glassfish&a=javax.faces&v=LATEST"相对=nofollow>实施链接提到有什么新的JSF 2.2罐子?

I'm not sure what's going on as I haven't seen this before. The following construct works for me when using the today's Mojarra 2.2.1 snapshot which you can download from the "implementation jar" link mentioned in What's new in JSF 2.2?

<h:form enctype="multipart/form-data">
    <h:inputFile value="#{bean.file}" required="true">
        <f:ajax listener="#{bean.handleFileUpload}" render="@form" />
    </h:inputFile>
    <h:messages />
</h:form>

private Part file;

public void handleFileUpload(AjaxBehaviorEvent event) {
    System.out.println("file size: " + file.getSize());
    System.out.println("file type: " + file.getContentType());
    System.out.println("file info: " + file.getHeader("Content-Disposition"));
}

// ...

我推荐给新Mojarra版本一试。显然有它没能创造一个合适的的multipart / form-data的在一个旧Mojarra版本中的错误使用要求&LT; IFRAME&GT; 黑客攻击,最终导致该错误。该 MXX 版本是测试版本不管怎样,因此不应依赖生产。这个错误在理论上也已经针对特定浏览器,但它现在对我很好在Chrome 26,火狐20和IE 10。

I recommend to give the newer Mojarra version a try. Apparently there was a bug in an older Mojarra version which failed to create a proper multipart/form-data request using the <iframe> hack which ultimately caused this error. The mXX versions are beta versions anyway and should not be relied upon for production. This error could theoretically also have been browser-specific, but it works currently fine for me in Chrome 26, Firefox 20 and IE 10.

而我看到的唯一问题是,隐藏&LT; IFRAME&GT; 仍然可见在Chrome和Firefox如下:

The only issue which I'm seeing is that the hidden <iframe> is still visible in Chrome and Firefox as below:

看来,他们忘记设置 FRAMEBORDER 属性 0 在生成的&LT; IFRAME&GT; 。我已经报问题2861 有关。

It appears that they're forgotten to set frameborder attribute to 0 in the generated <iframe>. I've reported issue 2861 about that.

这篇关于JSF 2.2 - 文件上传不与阿贾克斯的工作。形态似乎有不正确的enctype(只能通过AJAX)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆