java - 无法一起发送列表框和文件

标签 java gwt servlets gwt2 formpanel

您好,我正在使用 GWT 通过 servlet 发送文件。

最初我试图仅将文件发送到服务器。效果很好。

现在在 af ormPanel 中我添加了 3 个列表框。

private ListBox propertyNamelist = getListBox("propertyName");
    private ListBox propertyTypeList = getListBox("propertyType");
    private ListBox propertyValueList = getListBox("propertyValue");

private ListBox getListBox(String name){

            listbox = new ListBox();
            listbox.setName(name);

        return listbox;
    }

然后将其添加到 FormPanel。

formPanel.setWidget(propertyNamelist);
formPanel.setWidget(propertyTypeList);
formPanel.setWidget(propertyValueList);
formPanel.submit();

在服务器端。

try {

        ServletFileUpload upload = new ServletFileUpload();

        FileItemIterator iterator = upload.getItemIterator(request);
        while (iterator.hasNext()) {
            FileItemStream item = iterator.next();
             stream = item.openStream();

            if (item.isFormField()) {
                log.warning("Got a form field: " + item.getFieldName());
                System.out.println(" chk fg " +item.getFieldName() +"  =  "+ Streams.asString(item.openStream()));


            } else {

                log.warning("Got an uploaded file: " + item.getFieldName()
                        + ", name = " + item.getName());
                fileName = item.getName();
                mimetype = item.getContentType();

            }
        }

    }catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

输出:

WARNING: Got a form field: propertyValue
Jun 11, 2012 11:37:55 AM com.google.apphosting.utils.jetty.JettyLogger warn
WARNING: /UploadFileServlet: org.apache.commons.fileupload.FileItemStream$ItemSkippedException
 chk fg propertyValue  =  motivation

根据我的动机是列表框PropertyValue的第一个值,因为列表框中还有更多值。

还有更多的列表框需要显示。

我无法理解正在发生的事情。

注意:我无法通过 RPC 发送列表框,因为这些列表框与要发送到服务器和服务器到外部存储库的文件相关。

请有人帮忙。

最佳答案

顾名思义,FormPanel 上的 setWidget 会替换 FormPanel 小部件的内容。

您想要将多个小部件放入 FormPanel 中,因此请使用中间容器(例如 FlowPanel)将您的小部件放入:

// put all widgets together in some container (you can have a more complex layout)
FlowPanel container = new FlowPanel();
container.add(fileUpload);
container.add(propertyNameList);
container.add(propertyTypeList);
container.add(propertyValueList);

// set the container as the content of the form, so named form widgets will get
// their value sent to the server.
formPanel.setWidget(container);

关于java - 无法一起发送列表框和文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10978335/

相关文章:

css - 使用客户端包中定义的图像作为背景图像

java - 有没有一个java程序来检查2个组合句子是否有意义?

java - Proguard obfuscate only/WEB-INF/classes/**/*.class 文件在我的 war 中

java - 无法通过延迟绑定(bind)创建...的实例

java - web片段和web.xml中servlet监听器的执行顺序

java - 什么是适合与 Vaadin 一起使用的紧凑、可嵌入的 Servlet 容器?

java - 使用 Java 跨不同域的单点登录 [SSO]

java - jcombobox 中的复选框 : never checked

java - OOAD设计问题

setValue(true) 时 gwt 复选框触发处理程序