English 中文(简体)
使用RequestBuilder上传文件。
原标题:File Upload with RequestBuilder

我需要在GWT中在后台上传文件,即不使用可视化部件。

就我而言,我发现了“请购单”类别,但几乎没有关于如何将其用于上载目的的文件。

我需要上传的文件内容是100%纯文本。

迄今为止,我的代码看起来像这样:

final String filename = UUID.randomUUID().toString() + ".txt";

RequestBuilder rb = new RequestBuilder(RequestBuilder.POST, "http://localhost/upload");
rb.setRequestData(selected.getBody()); // getBody() is plain-text
rb.setHeader("Content-Type", "application/x-www-form-urlencodeddata");
rb.setCallback(new RequestCallback() {
    @Override
    public void onResponseReceived(Request request, Response response) {
        w.setUrl("http://localhost/magic.html?hide=status&open=" + filename);
        w.show();
        w.maximize();                            
    }

    @Override
    public void onError(Request request, Throwable exception) {
        exception.printStackTrace();
    }
});

// Checked Exceptions sucks *sigh*
try {
    rb.send();
}
catch (RequestException e) {
    e.printStackTrace();
}

我希望有人能给我一些解决这个问题的指导意见,谢谢!

最佳回答

我认为使用JavaScript仅仅是不可能在没有用户交互的情况下上传文件到服务器的。我认为这是由于浏览器屏蔽了此功能,因为这意味着当你访问某个网站时,任何人都可以上传你系统中的任何文件,这将成为一个重大安全问题。我不知道你为什么想这么做,但我猜你需要寻找另一种方法来解决你想做的事情。

问题回答

看起来你可以使用Gears上传文件,所以在最坏的情况下,你可以使用JavaScript实现这样的功能:链接文本





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签