欢迎来到天天文库
浏览记录
ID:34761254
大小:61.48 KB
页数:11页
时间:2019-03-10
《实现图片上载服务器》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、我这里就写两个例子:Eg1:电商网站分前台和后台,后台维护商品和供应商即后台上传图片前台展示,现在要求前台部署在A服务器,前台部署在B服务器上且用nginx做图片服务器并将nginx服务装在A服务器上,图片上传到A服务器本地xx文件夹下。这中情况就很简单,我们只需要将后台上传图片的url设置为A服务本地创建的xx文件,并修改conf/nginx.conf中server{listen80;server_name127.0.0.1;#charsetkoi8-r;#access_loglogs/host.access.logmain;location/ekaImage/{aliasD:e
2、kaImage;}前台访问时直接http://A服务IP:ekaImage/XX/xx.jpg即可Eg2:后台服务部署在A服务器上,前台部署在B服务器,图片服务器部署在C服务器上我们是单独将图片上传写了个APP部署在C服务器然后后台上传图片是调C服务器部署的图片服务器应用提供的上传图片的方法并将图片存放在C服务器的本地文件夹xxx下且在nginx.conf里修改为C服务器IP,前台访问时直接按http:+C服务器IP+文件路径+图片路径图片服务器应用:packagecom.nginx.service;importjava.io.File;importjava.io.FileOutpu
3、tStream;importjava.io.IOException;importjava.util.Iterator;importjava.util.List;importjavax.servlet.ServletException;importjavax.servlet.http.HttpServlet;importjavax.servlet.http.HttpServletRequest;importjavax.servlet.http.HttpServletResponse;importorg.apache.commons.fileupload.FileItem;importo
4、rg.apache.commons.fileupload.FileItemFactory;importorg.apache.commons.fileupload.FileUploadException;importorg.apache.commons.fileupload.disk.DiskFileItemFactory;importorg.apache.commons.fileupload.servlet.ServletFileUpload;importorg.apache.log4j.Logger;/***ServletimplementationclassnginxServle
5、t*/publicclassnginxServletextendsHttpServlet{privateLoggerlogger=Logger.getLogger(nginxServlet.class);privatestaticfinallongserialVersionUID=1L;/***@seeHttpServlet#HttpServlet()*/publicnginxServlet(){super();logger.info("nginxServletinit..........");}/***@seeHttpServlet#doGet(HttpServletRequest
6、request,HttpServletResponseresponse)*/protectedvoiddoGet(HttpServletRequestrequest,HttpServletResponseresponse)throwsServletException,IOException{logger.info("nginxServletdoGet............................");doPost(request,response);}/***@seeHttpServlet#doPost(HttpServletRequestrequest,HttpServl
7、etResponseresponse)*/protectedvoiddoPost(HttpServletRequestrequest,HttpServletResponseresponse)throwsServletException,IOException{logger.info("nginxServletdoPost............................");FileItemFactoryfactory=newDiskFileItem
此文档下载收益归作者所有