vaadin中的文件上传和下载
File upload and download in vaadin
我对 Vaadin 非常陌生。我通过查看 Github 和其他文档来设置项目,其中我使用 Spring-security、Vaadin、Maven。
我用 spring 安全项目创建了示例 vaadin-maven。现在正在获取登录页面,然后在成功登录后,正在获取一些 MainView.java.
我正在尝试更改上传的 .xls 文件并读取该文件并执行一些功能,然后下载弹出窗口。
我已经关注了http://demo.vaadin.com/sampler/#ui/data-input/other/upload,但是有错误。无法重现我的输出。
目前,我可以使用路径“final String FILE_PATH = "F://input.xls";”读取文件但是,我需要上传文件的选项,然后使用该文件获得更多功能。
功能完成后,我需要下载文件。
请建议我如何浏览文件并上传并使用上传的文件进行一些读写操作,然后下载 Vaadin。
为此我失眠了。请建议我如何解决这个问题。
这是我的代码:
@Component
@Scope("prototype")
@VaadinView(RoleAdminView.NAME)
@Secured("ROLE_ADMIN")
public class RoleAdminView extends Panel implements View
{
public static final String NAME = "role_admin";
@PostConstruct
public void PostConstruct()
{
LoggerFactory.getLogger(this.getClass()).debug("POST");
setSizeFull();
VerticalLayout layout = new VerticalLayout();
layout.setSpacing(true);
layout.setMargin(true);
layout.addComponent(new Button());
layout.addComponent(new Label("ROLE_ADMIN"));
layout.addComponent(new Link("Go back", new ExternalResource("#!" +
MainView.NAME)));
setContent(layout);
}
@Override
public void enter(ViewChangeListener.ViewChangeEvent event)
{
}
}
非常感谢您。希望你们解决我的问题:)
你可以的,
public class RoleAdminView extends Panel implements View{
//add a button view
//
@Override
public void uploadFailed(Upload.FailedEvent event) {
Notification.show(event.getFilename() + "----" + event.getMIMEType());
//here it will show the error if upload failed
}
@Override
public void uploadSucceeded(SucceededEvent event) {
/// do your functionlity
}
@Override
public OutputStream receiveUpload(String filename, String mimeType) {
FileOutputStream fos = null;
// do your functionality to save in any path or server path
return fos; // Return the output stream to write to
}
}
希望对你有所帮助:)
我对 Vaadin 非常陌生。我通过查看 Github 和其他文档来设置项目,其中我使用 Spring-security、Vaadin、Maven。
我用 spring 安全项目创建了示例 vaadin-maven。现在正在获取登录页面,然后在成功登录后,正在获取一些 MainView.java.
我正在尝试更改上传的 .xls 文件并读取该文件并执行一些功能,然后下载弹出窗口。
我已经关注了http://demo.vaadin.com/sampler/#ui/data-input/other/upload,但是有错误。无法重现我的输出。
目前,我可以使用路径“final String FILE_PATH = "F://input.xls";”读取文件但是,我需要上传文件的选项,然后使用该文件获得更多功能。
功能完成后,我需要下载文件。
请建议我如何浏览文件并上传并使用上传的文件进行一些读写操作,然后下载 Vaadin。
为此我失眠了。请建议我如何解决这个问题。 这是我的代码:
@Component
@Scope("prototype")
@VaadinView(RoleAdminView.NAME)
@Secured("ROLE_ADMIN")
public class RoleAdminView extends Panel implements View
{
public static final String NAME = "role_admin";
@PostConstruct
public void PostConstruct()
{
LoggerFactory.getLogger(this.getClass()).debug("POST");
setSizeFull();
VerticalLayout layout = new VerticalLayout();
layout.setSpacing(true);
layout.setMargin(true);
layout.addComponent(new Button());
layout.addComponent(new Label("ROLE_ADMIN"));
layout.addComponent(new Link("Go back", new ExternalResource("#!" +
MainView.NAME)));
setContent(layout);
}
@Override
public void enter(ViewChangeListener.ViewChangeEvent event)
{
}
}
非常感谢您。希望你们解决我的问题:)
你可以的,
public class RoleAdminView extends Panel implements View{
//add a button view
//
@Override
public void uploadFailed(Upload.FailedEvent event) {
Notification.show(event.getFilename() + "----" + event.getMIMEType());
//here it will show the error if upload failed
}
@Override
public void uploadSucceeded(SucceededEvent event) {
/// do your functionlity
}
@Override
public OutputStream receiveUpload(String filename, String mimeType) {
FileOutputStream fos = null;
// do your functionality to save in any path or server path
return fos; // Return the output stream to write to
}
}
希望对你有所帮助:)