Monday, June 7, 2010

Yokohama

Japanese Chinatown

Finally figured out that was Hello Kitty in a panda suit, and not a panda choking on his 3 toungues. Took a while though.

I think they sold pandas, or tires. Maybe both.


Please rob us. We are not from around here.

Someone likes dragons


And Ligers, which are bred for their skills in magic.

Typical street in Chi-pan

Wind turbine in Port of Yokohama

Shinko district and Yokohama Cosmo World

Fishwall

Osanbashi Pier (Yokohama Terminal)

Osanbashi Pier

O.P.

O.P.

Will and Aya chillin at Subzero

Of course we had to stop here for a beer

Yokohama Terminal

People love to pose for the camera. Or was he telling me not to take pictures of them? I have no idea.

Can someone please send me some American Gladiator pugils so I can challenge unsuspecting passerbys?
View of Yokohama out one side of the Landmark tower's 69th floor "Sky Garden." The elevator climbs at 750 meters per minute (and was at one time not that long ago the worlds fastest)

View out the other side

Another side

Across the waterfront. Interesting to note that much of this land has been reclaimed from the sea. And it seems more is being added every year.

Road level(s)
Shadow from the Landmark Tower

Everyone was in a posing mood today

Even Will.

How do you make Grimmace jealous?

Panorama of the Port of Yokohama

Guess where

First person to guess where this sign is posted wins.
The answer is apparently Cappy spends entirely too much time here when he visits. And yes it is the mens room.

Monday, May 24, 2010

File upload menggunakan JSP

Dalam suatu sistem aplikasi berbasis web tidak lengkap tanpa adanya fungsi untuk mengupload file. Seperti halnya untuk mengupload file lampiran, foto, hasil scan, file exe. dan berbagai jenis file lainnya dimana dibutuhkan bagi pengguna untuk kepentingan share dan dokumentasi.

Pada yahoo klasik atau upload foto pada blogspot ini, dapat kita temukan fungsi untuk mengupload file attachment atau gambar. Namun pada Yahoo klasik metode upload yang digunakan masih menggunakan file upload yang konvensional / sederhana. Berbeda dengan Yahoo mail beta atau pada facebook dimana menggunakan metode yang lebih canggih dalam hal mengupload gambar.


Mungkin pada sisi back-end kode yang dipakai tetap sama dengan metode konvensional namun perbedaan pada sisi kode tampilan. pada tampilan menggunakan teknologi javascript - AJAX.

Untuk implementasi fungsi back-end file upload, bermacam-macam cara yang tersedia, seperti menggunakan library common.fileUpload bawaan apache tomcat maupun library lain atau hanya dengan file input outstream (java.io). Berikut contoh sederhana menggunakan java.io.

Ada dua file yang perlu disediakan. pertama, file html yang merupakan halaman untuk memilih file yang akan diupload.

upload.html


<form action="upload.jsp" method="POST" enctype="multipart/form-data">
<!-- enctype="multipart/form-data" -->
<input type="file" name="theFile"><br>

<input type="submit">
</form>


upload.jsp


<!-- upload.jsp -->
<%@ page import="java.io.*" %>

<%
String contentType = request.getContentType();
System.out.println("Content type is :: " +contentType);
if ((contentType != null) && (contentType.indexOf("multipart/form-data") >= 0)) {
DataInputStream in = new DataInputStream(request.getInputStream());
int formDataLength = request.getContentLength();

byte dataBytes[] = new byte[formDataLength];
int byteRead = 0;
int totalBytesRead = 0;
while (totalBytesRead < formDataLength) {
byteRead = in.read(dataBytes, totalBytesRead, formDataLength);
totalBytesRead += byteRead;
}

String file = new String(dataBytes);
String saveFile = file.substring(file.indexOf("filename=\"") + 10);
//out.print("FileName:" + saveFile.toString());
saveFile = saveFile.substring(0, saveFile.indexOf("\n"));
//out.print("FileName:" + saveFile.toString());
saveFile = saveFile.substring(saveFile.lastIndexOf("\\") + 1,saveFile.indexOf("\""));
//out.print("FileName:" + saveFile.toString());

//out.print(dataBytes);

int lastIndex = contentType.lastIndexOf("=");
String boundary = contentType.substring(lastIndex + 1,contentType.length());
//out.println(boundary);
int pos;
pos = file.indexOf("filename=\"");

pos = file.indexOf("\n", pos) + 1;

pos = file.indexOf("\n", pos) + 1;

pos = file.indexOf("\n", pos) + 1;


int boundaryLocation = file.indexOf(boundary, pos) - 4;
int startPos = ((file.substring(0, pos)).getBytes()).length;
int endPos = ((file.substring(0, boundaryLocation)).getBytes()).length;
saveFile = "/Users/ansis/Documents/NetBeansProjects/statis/build/web/doc/" + saveFile;

FileOutputStream fileOut = new FileOutputStream(saveFile);


//fileOut.write(dataBytes);
fileOut.write(dataBytes, startPos, (endPos - startPos));
fileOut.flush();
fileOut.close();

out.println("File saved as " +saveFile);
}
%>

Berikut screenshot tampilan upload.html :


tampilan upload.jsp :


Sekian sedikit penjelasan cara membuat file upload menggunakan JSP secara sederhana. Pada posting selanjutnya aka dijelaskan implementasi file upload pada extjs.

HaRaJuKu I Love U





HaRaJuKu I Love U



BrAnDoN dE aNGeLo

HaRaJuKu I Love U