//사진 가져오기를 누르면 실행되는 곳
public void callGallery(View v){
      	
			Intent intent = new Intent();
			intent.setAction(Intent.ACTION_GET_CONTENT);
			intent.setType("image/*");
			startActivityForResult(intent, TAKE_GALLERY);
    }
//이곳으로 이동해서
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
	if(requestCode == TAKE_GALLERY){
			    	
			    
			    	if( data != null ){
			    		//final Bundle extras = data.getExtras();
			    		//Bitmap photo = extras.getParcelable("data");
		    			Uri thumbnail = data.getData();
		    			
		        		if( photo != null ){      // 가지고온 사진 데이터를 이미지 뷰에 보여 준다.
		        			
		        			imageView.setImageBitmap(photo);
		        			Uri currImageURI = data.getData();
							textView.setText("GALLERY : " + getRealPathFromURI(currImageURI));
		        		}
		    		}
	}
}
//전송하기 버튼을 누르면
 public void sendPost(View v) throws IOException {
 		  
		this.progressDialog = ProgressDialog.show(this, " 전송 중..",
		    "시간이 좀 걸려요:)", true, false);
		  new Thread(new Runnable() {
		   @Override
		   public void run() {
			 //선택한 이미지의 uri를 읽어온다.   
		    	 Uri selPhotoUri = data.getData();
			 //업로드할 서버의 url 주소
	    	     String urlString = "http://58.103.20.246:5000/NearMap/saveImage.jsp";
	    	     //절대경로를 획득한다!!! 중요~
	    	     Cursor c = getContentResolver().query(Uri.parse(selPhotoUri.toString()), null,null,null,null);
	    	     c.moveToNext();
	    	     //업로드할 파일의 절대경로 얻어오기("_data") 로 해도 된다.
	    	     String absolutePath = c.getString(c.getColumnIndex(MediaStore.MediaColumns.DATA));
	    	     //Toast.makeText(MainActivity.this, absolutePath, 0).show();
	    	    //파일 업로드 시작!
	    	     HttpFileUpload1("http://58.103.20.246:5000/NearMap/saveImage.jsp", "", absolutePath);	
		    confirmHandler.sendEmptyMessage(0);
		   }
		  }).start();
//이미지 전송하는 부분
private void HttpFileUpload1(String urlString, String params, String fileName) {
		try {
			
			mFileInputStream = new FileInputStream(fileName);			
			connectUrl = new URL("urlString);
			Log.d("Test", "mFileInputStream  is " + mFileInputStream);
			
			// open connection 
			HttpURLConnection conn = (HttpURLConnection)connectUrl.openConnection();			
			conn.setDoInput(true);
			conn.setDoOutput(true);
			conn.setUseCaches(false);
			conn.setRequestMethod("POST");
			conn.setRequestProperty("Connection", "Keep-Alive");
			conn.setRequestProperty("Content-Type", "multipart/form-data;boundary=" + boundary);
			
			// write data
			DataOutputStream dos = new DataOutputStream(conn.getOutputStream());
			dos.writeBytes(twoHyphens + boundary + lineEnd);
			dos.writeBytes("Content-Disposition: form-data; name=\"uploadedfile\";filename=\"" + fileName+"\"" + lineEnd);
			dos.writeBytes(lineEnd);
			
			int bytesAvailable = mFileInputStream.available();
			int maxBufferSize = 1024;
			int bufferSize = Math.min(bytesAvailable, maxBufferSize);
			
			byte[] buffer = new byte[bufferSize];
			int bytesRead = mFileInputStream.read(buffer, 0, bufferSize);
			
			Log.d("Test", "image byte is " + bytesRead);
			
			// read image
			while (bytesRead > 0) {
				dos.write(buffer, 0, bufferSize);
				bytesAvailable = mFileInputStream.available();
				bufferSize = Math.min(bytesAvailable, maxBufferSize);
				bytesRead = mFileInputStream.read(buffer, 0, bufferSize);
			}	
			
			dos.writeBytes(lineEnd);
			dos.writeBytes(twoHyphens + boundary + twoHyphens + lineEnd);
			
			// close streams
			Log.e("Test" , "File is written");
			mFileInputStream.close();
			dos.flush(); // finish upload...			
			
			// get response
			int ch;
			InputStream is = conn.getInputStream();
			StringBuffer b =new StringBuffer();
			while( ( ch = is.read() ) != -1 ){
				b.append( (char)ch );
			}
			String s=b.toString(); 
			Log.e("Test", "result = " + s);
			dos.close();			
			
		} catch (Exception e) {
			Log.d("Test", "exception " + e.getMessage());
			// TODO: handle exception
		}		
}
//이곳은 파일을 받아주는 jsp파일입니다.
<%@page import="com.oreilly.servlet.multipart.DefaultFileRenamePolicy"%>
<%@page import="com.oreilly.servlet.MultipartRequest"%>
<%@ page pageEncoding="UTF-8"%>
<%
	String dir = application.getRealPath("upload");
	int max = 5*1024*1024;
	
	//최대크기, dir 디렉토리에 파일을 업로드하는 multipartRequest
	
	MultipartRequest mr = new MultipartRequest(request, dir, max, "UTF-8", new DefaultFileRenamePolicy());
	String orgFileName = mr.getOriginalFileName("file1");
	String saveFileName = mr.getFilesystemName("file1");
	System.out.println(orgFileName+"이 저장되었습니다.");
%>