国产一级a片免费看高清,亚洲熟女中文字幕在线视频,黄三级高清在线播放,免费黄色视频在线看

打開APP
userphoto
未登錄

開通VIP,暢享免費(fèi)電子書等14項(xiàng)超值服

開通VIP
hadoop網(wǎng)盤小項(xiàng)目介紹及相關(guān)代碼下載1
問題導(dǎo)讀


1.本文安裝了哪些軟件?
2.使用了Java什么技術(shù)?


hadoop作為網(wǎng)盤,不是最好的,但是作為練手還是可以的。同時(shí)hadoop作為網(wǎng)盤實(shí)現(xiàn)方式有多種,本例子,使用的是Java api,當(dāng)然使用rest api同樣是可以的。
詳細(xì)參考下面:

hadoop網(wǎng)盤的最終效果見下面,可以實(shí)現(xiàn)簡單的文件上傳、刪除、下載功能,不同用戶可以登錄到自己的頁面進(jìn)行管理。
 
一、準(zhǔn)備的安裝包資源
(1)hadoop1.1.2安裝包
 

(2)bootmetro一個(gè)CSS開元框架,用來提高web前端的開發(fā)效率
 

(3)mysql的Jdbc驅(qū)動(dòng)包


(4)上傳組件
 
(5)mysql安裝包(我的電腦是x64,x86系統(tǒng)的請(qǐng)下載對(duì)應(yīng)版本即可)

 
二、搭建hadoop集群環(huán)境
教程見(2)虛擬機(jī)下hadoop1.1.2集群環(huán)境搭建

三、mysql5.6安裝和eclipse上的配置
(1)安裝教程網(wǎng)上很多,這里就不詳細(xì)列舉,大家到網(wǎng)上搜索即可。
A、安裝好后,把mysql安裝文件夾下的bin目錄的路徑添加到PATH環(huán)境變量里。
 
B、然后打開cmd,輸入mysqld,開啟mysql服務(wù)。
C、創(chuàng)建hadoop數(shù)據(jù)庫
打開cmd,輸入:mysql -uroot -hlocalhost -p
然后會(huì)提示輸入密碼:密碼默認(rèn)為空,所以直接回車就可以進(jìn)入Mysql命令行。
接下來輸入:create database hadoop;就創(chuàng)建成功
我們輸入:show databases; 來查看
 
(2)在eclipse上配置mysql
A、首先打開eclipse,創(chuàng)建web工程。
 
B、把mysql-connector-java-commercial-5.1.25.jar包復(fù)制到在WEB-INF/lib下。
 
C、鏈接hadoop數(shù)據(jù)庫
在Window菜單欄下打開Open Perspertive,選擇 Database Development。
 
然后再Database Connections文件夾下郵件選擇New ..;
 
然后再URL上填上剛剛創(chuàng)建的hadoop數(shù)據(jù)庫;
 
點(diǎn)擊 Test Connection,測試鏈接成功。
四、fileupload控件實(shí)現(xiàn)文件的上傳
(1)首先將commons-fileupload-1.3.1.jar和commons-io-2.4.jar復(fù)制到WEB-INF/lib目錄下。
(2)在WebContent/下創(chuàng)建inedx.jsp文件用于上傳文件。
  1. <%@ page language="java" contentType="text/html; charset=UTF-8"
  2.     pageEncoding="UTF-8"%>
  3. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  4. <html>
  5. <head>
  6. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  7. <title>Insert title here</title>
  8. </head>
  9. <body>
  10.            <form class="form-inline"  method="POST"  enctype="MULTIPART/FORM-DATA"   action="UploadServlet" >
  11.                    <div style="line-height:50px;float:left;">
  12.                             <input type="submit" name="submit" value="上傳文件"  />
  13.                    </div>  
  14.                    <div style="line-height:50px;float:left;">
  15.                             <input type="file" name="file1" size="30"/>
  16.                    </div>  
  17. </form>
  18. </body>
  19. </html>
復(fù)制代碼





然后再創(chuàng)建一個(gè)UploadServlet處理上傳的文件。
 

  1. package com.controller;

  2. import java.io.File;
  3. import java.io.IOException;
  4. import java.util.Iterator;
  5. import java.util.List;

  6. import javax.servlet.ServletContext;
  7. import javax.servlet.ServletException;
  8. import javax.servlet.http.HttpServlet;
  9. import javax.servlet.http.HttpServletRequest;
  10. import javax.servlet.http.HttpServletResponse;
  11. import javax.servlet.<a target="_blank" class="keylink">jsp</a>.PageContext;

  12. import org.apache.commons.fileupload.DiskFileUpload;
  13. import org.apache.commons.fileupload.FileItem;
  14. import org.apache.commons.fileupload.disk.DiskFileItemFactory;
  15. import org.apache.commons.fileupload.servlet.ServletFileUpload;



  16. /**
  17. * Servlet implementation class UploadServlet
  18. */
  19. public class UploadServlet extends HttpServlet {

  20.         /**
  21.          * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
  22.          */
  23.         protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
  24.                 this.doPost(request, response);
  25.         }

  26.         /**
  27.          * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
  28.          */
  29.         protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
  30.                    request.setCharacterEncoding("UTF-8");
  31.                    File file ;
  32.                    int maxFileSize = 50 * 1024 *1024;  //50M
  33.                    int maxMemSize = 50 * 1024 *1024;    //50M
  34.                    ServletContext context = getServletContext();
  35.                    String filePath = context.getInitParameter("file-upload");
  36.                         System.out.println("source file path:"+filePath+"");
  37.                    // 驗(yàn)證上傳內(nèi)容了類型
  38.                    String contentType = request.getContentType();
  39.                    if ((contentType.indexOf("multipart/form-data") >= 0)) {

  40.                       DiskFileItemFactory factory = new DiskFileItemFactory();
  41.                       // 設(shè)置內(nèi)存中存儲(chǔ)文件的最大值
  42.                       factory.setSizeThreshold(maxMemSize);
  43.                       // 本地存儲(chǔ)的數(shù)據(jù)大于 maxMemSize.
  44.                       factory.setRepository(new File("c:\\temp"));

  45.                       // 創(chuàng)建一個(gè)新的文件上傳處理程序
  46.                       ServletFileUpload upload = new ServletFileUpload(factory);
  47.                       // 設(shè)置最大上傳的文件大小
  48.                       upload.setSizeMax( maxFileSize );
  49.                       try{ 
  50.                          // 解析獲取的文件
  51.                          List fileItems = upload.parseRequest(request);

  52.                          // 處理上傳的文件
  53.                          Iterator i = fileItems.iterator();

  54.                          System.out.println("begin to upload file to tomcat server</p>"); 
  55.                          while ( i.hasNext () ) 
  56.                          {
  57.                             FileItem fi = (FileItem)i.next();
  58.                             if ( !fi.isFormField () )        
  59.                             {
  60.                             // 獲取上傳文件的參數(shù)
  61.                             String fieldName = fi.getFieldName();
  62.                             String fileName = fi.getName();
  63.                             
  64.                             String fn = fileName.substring( fileName.lastIndexOf("\\")+1);
  65.                             System.out.println("<br>"+fn+"<br>");
  66.                             boolean isInMemory = fi.isInMemory();
  67.                             long sizeInBytes = fi.getSize();
  68.                             // 寫入文件
  69.                             if( fileName.lastIndexOf("\\") >= 0 ){
  70.                             file = new File( filePath , 
  71.                             fileName.substring( fileName.lastIndexOf("\\"))) ;
  72.                             //out.println("filename"+fileName.substring( fileName.lastIndexOf("\\"))+"||||||");
  73.                             }else{
  74.                             file = new File( filePath ,
  75.                             fileName.substring(fileName.lastIndexOf("\\")+1)) ;
  76.                             }
  77.                             fi.write( file ) ;
  78.                             System.out.println("upload file to tomcat server success!");
  79.                             
  80.                             request.getRequestDispatcher("index.<a target="_blank" class="keylink">jsp</a>").forward(request, response);
  81.                             
  82.                             }
  83.                          }
  84.                       }catch(Exception ex) {
  85.                          System.out.println(ex);
  86.                       }
  87.                    }else{
  88.                       System.out.println("<p>No file uploaded</p>"); 
  89.                 
  90.                    }
  91.          
  92.               
  93.                  
  94.         }

  95. }
復(fù)制代碼




然后再web.xml下設(shè)置上傳的路徑:
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
  3.   <display-name>TestHadoop</display-name>
  4.   <welcome-file-list>
  5.     <welcome-file>index.html</welcome-file>
  6.     <welcome-file>index.htm</welcome-file>
  7.     <welcome-file>index.jsp</welcome-file>
  8.     <welcome-file>default.html</welcome-file>
  9.     <welcome-file>default.htm</welcome-file>
  10.     <welcome-file>default.jsp</welcome-file>
  11.   </welcome-file-list>
  12.   <servlet>
  13.     <description></description>
  14.     <display-name>UploadServlet</display-name>
  15.     <servlet-name>UploadServlet</servlet-name>
  16.     <servlet-class>com.controller.UploadServlet</servlet-class>
  17.   </servlet>
  18.   <context-param>
  19.     <description>Location to store uploaded file</description>
  20.     <param-name>file-upload</param-name>
  21.     <param-value>
  22.          D:\apache-tomcat-6.0.41\webapps\data
  23.      </param-value>
  24.   </context-param>
  25.   <servlet-mapping>
  26.     <servlet-name>UploadServlet</servlet-name>
  27.     <url-pattern>/UploadServlet</url-pattern>
  28.   </servlet-mapping>
  29. </web-app>
復(fù)制代碼





我們測試一下是否可以上傳,我現(xiàn)在將上傳(1)Centos6.5下hadoop1.1.2環(huán)境搭建(單機(jī)版).docx文件;
 
我們到
  1. D:\apache-tomcat-6.0.41\webapps\data
復(fù)制代碼


可以看到文件已經(jīng)上傳成功。

 










參考http://www.it165.net/admin/html/201408/3580.html
本站僅提供存儲(chǔ)服務(wù),所有內(nèi)容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊舉報(bào)
打開APP,閱讀全文并永久保存 查看更多類似文章
猜你喜歡
類似文章
Java Servlet – jQuery File Upload (multiple, drag&drop, progress…) | HMKCode
commonds-fileupload-kirin -JavaEye技術(shù)社區(qū)
文件上傳
java上傳圖片文件
Java文件上傳與下載【面試+工作】
Web基礎(chǔ)了解版12-上傳下載
更多類似文章 >>
生活服務(wù)
分享 收藏 導(dǎo)長圖 關(guān)注 下載文章
綁定賬號(hào)成功
后續(xù)可登錄賬號(hào)暢享VIP特權(quán)!
如果VIP功能使用有故障,
可點(diǎn)擊這里聯(lián)系客服!

聯(lián)系客服