bl双性强迫侵犯h_国产在线观看人成激情视频_蜜芽188_被诱拐的少孩全彩啪啪漫画

servlet中怎么實(shí)現(xiàn)圖片上傳功能-創(chuàng)新互聯(lián)

本篇文章給大家分享的是有關(guān)servlet中怎么實(shí)現(xiàn)圖片上傳功能,小編覺得挺實(shí)用的,因此分享給大家學(xué)習(xí),希望大家閱讀完這篇文章后可以有所收獲,話不多說,跟著小編一起來看看吧。

創(chuàng)新互聯(lián)公司專注于新密企業(yè)網(wǎng)站建設(shè),響應(yīng)式網(wǎng)站,成都商城網(wǎng)站開發(fā)。新密網(wǎng)站建設(shè)公司,為新密等地區(qū)提供建站服務(wù)。全流程按需設(shè)計,專業(yè)設(shè)計,全程項(xiàng)目跟蹤,創(chuàng)新互聯(lián)公司專業(yè)和態(tài)度為您提供的服務(wù)

一個簡單的servlet例子,實(shí)現(xiàn)圖片的上傳功能,上傳的圖片給 HttpServletResponse 對象

public class BackGroundLogoServlet extends HttpServlet{   private static final Logger m_logger=Logger.getLogger (BackGroundLogoServlet. class);      @Override   public void init(ServletConfig config) throws ServletException {      super.init(config);      m_logger.debug ( "BackGroundLogoServlet init.");   }      @Override   protected void doGet(HttpServletRequest request, HttpServletResponse response)         throws ServletException{        response.setContentType( "image/png");      response.setHeader( "Access-Control-Allow-Origin", "*");      String fileName = request.getParameter( "filename");//獲取參數(shù)值titlebar_logo.png      File file = new File( "D:\\"+ fileName);//讀取D:\\titlebar_logo.png圖片      FileInputStream fis = null;      BufferedOutputStream out= null;      try      {        fis = new FileInputStream(file);        out = new BufferedOutputStream(response.getOutputStream());        byte[] buffer= new byte[1024];        int len;        while((len=fis.read(buffer))!=-1)        {          //read the file from local disk          //write to client          out.write(buffer, 0, len);             out.flush();          m_logger.debug ( "background pic upload success !");        }      }      catch (FileNotFoundException e)      {        try        {          response.reset();          //set content type once again          response.setContentType("text/html;charset=utf-8" );          //give error message to client          response.getWriter().println( "文件未找到" );        }        catch (IOException e1)        {          e1.printStackTrace();        }        e.printStackTrace();      }      catch (IOException e)      {        e.printStackTrace();      }      finally      {        try        {          if(fis!= null){          fis.close();        }        if(out!= null){          out.close();        }      }      catch (IOException e)      {        e.printStackTrace();      }    }         }

以上就是servlet中怎么實(shí)現(xiàn)圖片上傳功能,小編相信有部分知識點(diǎn)可能是我們?nèi)粘9ぷ鲿姷交蛴玫降摹OM隳芡ㄟ^這篇文章學(xué)到更多知識。更多詳情敬請關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道。

當(dāng)前文章:servlet中怎么實(shí)現(xiàn)圖片上傳功能-創(chuàng)新互聯(lián)
URL分享:http://vcdvsql.cn/article20/jecjo.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供外貿(mào)網(wǎng)站建設(shè)、小程序開發(fā)建站公司網(wǎng)站收錄、手機(jī)網(wǎng)站建設(shè)、營銷型網(wǎng)站建設(shè)

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

綿陽服務(wù)器托管