有一个特殊的问题。
我正在使用FormPanel将数据发送到数据库并上传文件。
在Chrome中,这可以正常工作,但在Firefox中,它会将数据发送到数据库,但不会上传文件。 Firebug返回以下错误:
Form contains a file input, but is missing method=POST and enctype=multipart/form-data on the form. The file will not be sent.
我发现这很奇怪。 检查了页面源代码,一切似乎都很好:
<form target="FormPanel_revanweb_1" action="phpFiles/newBookmark.php" enctype="ENCODING_MULTIPART" method="POST" style="position: absolute; left: 0px; top: 0px; right: 0px; bottom: 0px;" class="gwt-TabLayoutPanelContent">
这是我使用UiBinder构建表单面板的方法:
<g:FormPanel ui:field="formPanel" action="phpFiles/newBookmark.php" method="POST" encoding="ENCODING_MULTIPART">
<g:VerticalPanel ui:field="tabNewWrapper" stylePrimaryName="tabNew-wrapper">
<g:HTMLPanel ui:field="bookmarkNamePanel" styleName="container">
<g:Label text="Bookmark Name:" />
<g:TextBox name="txtBookmarkName" ui:field="txtBookmarkName" width="100%" />
</g:HTMLPanel>
<g:HTMLPanel ui:field="bookmarkURLPanel" styleName="container">
<g:Label text="Bookmark URL:" styleName="label" />
<g:TextBox name="txtBookmarkURL" ui:field="txtBookmarkURL" width="100%" />
</g:HTMLPanel>
<g:HTMLPanel ui:field="bookmarkDescriptionPanel" styleName="container">
<g:Label text="Bookmark Description" styleName="label" />
<g:TextArea name="txtBookmarkDescription" ui:field="txtBookmarkDescription" width="100%" height="60px" />
</g:HTMLPanel>
<g:HTMLPanel ui:field="bookmarkImgUploadPanel" styleName="container">
<g:Label text="Image:" styleName="label" />
<g:VerticalPanel ui:field="vpForm">
<g:FileUpload name="logo" ui:field="uploadFile" />
</g:VerticalPanel>
</g:HTMLPanel>
<g:HTMLPanel ui:field="bookmarkcbActivePanel" styleName="container">
<g:CheckBox name="cbActive" ui:field="cbActive" text="Active?" styleName="label" />
</g:HTMLPanel>
<g:HTMLPanel ui:field="bookmarkTagsPanel" styleName="container">
<g:Label text="Tags:" styleName="label" />
<g:SuggestBox ui:field="sbBookmarkTags" animationEnabled="true" width="100%" />
</g:HTMLPanel>
<g:HTMLPanel ui:field="btnOKPanel" styleName="container">
<g:SubmitButton ui:field="btnSubmit" text="OK" styleName="buttonOK" />
<g:Label ui:field="lblWarning" visible="false" styleName="warning" />
<g:Hidden ui:field="sessionID" name="sessionid" visible="false" />
</g:HTMLPanel>
</g:VerticalPanel>
</g:FormPanel>
答案 0 :(得分:4)
您将编码设置为ENCODING_MULTIPART
,而不是multipart/form-data
。
注意:ENCODING_MULTIPART
是String
类型的常量,它不是枚举; setEncoding
上的FormPanel
以String
为参数;因此,如果您在ui.xml中编写ENCODING_MULTIPART,则将字符串设置为"ENCODING_MULTIPART"
,而不是FormPanel.ENCODING_MULTIPART
常量的值(btw,只能在ui.xml中使用<ui:import field="com.google.gwt.user.client.ui.FormPanel.ENCODING_MULTIPART" />
,然后用作{ENCODING_MULTIPART}
)