简体   繁体   English

用Java上传图片(struts2 / struts1 / spring mvc)

[英]Image Upload in java (struts2/struts1/spring mvc)

I have one website with jsp, java, struts2. 我有一个使用jsp,java,struts2的网站。 I wanted to upload a profile image into server . 我想将个人资料图片上传到服务器。 This is possible to upload into the server and link with the profile. 可以将其上传到服务器并与配置文件链接。 I want to store all the uploaded images in another server . 我想将所有上传的图像存储在另一台服务器中。 For example server A hosts the java web application. 例如,服务器A托管Java Web应用程序。 server B is a purchased space server and I want to upload the images from web application to server B. And the path and link 'll keep in server A database. 服务器B是购买的空间服务器,我想将图像从Web应用程序上传到服务器B。并且路径和链接将保留在服务器A数据库中。 Is it possible to do this same or any better idea is appreciated. 是否有可能做同样的事情或任何更好的主意受到赞赏。

Thanks in advance. 提前致谢。

This is a very popular design. 这是一个非常受欢迎的设计。 Consider the fact that if one of the two servers (A or B) is down, your site will not work, unless server B is mirrored properly. 考虑以下事实:如果两个服务器(A或B)之一关闭,则除非服务器B正确镜像,否则您的站点将无法工作。

Links to images can be anywhere on the web, as long as you provide the full path in the link. 只要在链接中提供完整路径,图像链接就可以在网络上的任何地方。 Also, make sure that server B can withstand the load, since every request for a page on server A with a link to an image on server B will obviously require both servers to respond. 另外,请确保服务器B能够承受负载,因为对服务器A上的页面的每个请求(带有链接到服务器B上的图像的请求)显然都需要两个服务器都进行响应。

Yes , I have found the solution. 是的,我找到了解决方案。 Approach #1: In java application you can upload your image to your current server(A) and store with c://somefolder/ . 方法1:在Java应用程序中,您可以将图像上传到当前服务器(A)并使用c:// somefolder /进行存储。 Then from the java application transfer the image using httpclient to a different server (B) which is in php/mysql and another domain name.(Php process is easy to store and access). 然后从Java应用程序中使用httpclient将图像传输到位于php / mysql和另一个域名中的另一台服务器(B)(Php流程易于存储和访问)。 After the transfer process get the result ,file name ,url and store it with your server A database. 传输过程完成后,获取结果,文件名,URL并将其存储在服务器A数据库中。 And in successful transfer delete the file from server A folder. 并成功传输后,从服务器A文件夹中删除文件。 Now u can user the image path as server B domainname/appname/imagepath . 现在,您可以将映像路径用作服务器B domainname / appname / imagepath。

Approach #2: The same process you can use with amazon web services. 方法2:您可以对亚马逊网络服务使用相同的过程。 (if you don't want to use the second domain name of yours. (如果您不想使用您的第二个域名。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM