使用Spring MVC在服务器上上传pdf [英] Upload pdf on a server with Spring MVC

查看:374
本文介绍了使用Spring MVC在服务器上上传pdf的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试创建一个网站,它将提供一个选项给用户上传PDF文件。我希望这个pdf被保存在具有特定网址的服务器上。例如:

用户选择标题。



用户上传文件。



我希望在这些操作之后,文件可以通过特定的url / name_the_user_give进行访问。我看到Spring MVC提供了非常好的简单的文件上传界面。我已经看到很多这方面的教程,但我的问题是我怎样才能将纸张保存到服务器。另外我想通过浏览器的工具打开pdf。可以任何人给我指示吗?

解决方案

为了将文件保存在服务器路径中,您只需将文件流写入到

  request.getServletContext()。getRealPath(your directory name here); 

然后使用您得到的真实路径创建文件。



要使用浏览器插件显示pdf文件,您应该在您的控制器方法中使用以下内容:

  RequestMapping(value =url to map,产生= {application / pdf})

这可以帮助你。



干杯。


i try to create a web site where it will provide an option to the user to upload a pdf file. I want this pdf to be saved on the server with specific url. For example:

The user select the title.

The user upload the file.

I want after these actions the file to be accessible via a specific url/name_the_user_give.

I saw that the Spring MVC provides very easy interface for file uploading.I already see many tutorial about this but my problem is how can i save the paper into a server.Also i want the pdf to open by the browser's tools.Can anyone give me directions?

解决方案

To save the file on server path you simply needs to write the file stream to the path described by

request.getServletContext().getRealPath("your directory name here");

and then create the file using the real path you get.

And to show the pdf file using browser plugin, you should use following in your controller method.

@RequestMapping(value="url to map", produces={"application/pdf"})

Hope this helps you.

Cheers.

这篇关于使用Spring MVC在服务器上上传pdf的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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