This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes JSP and the fly likes File Uploading Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "File Uploading" Watch "File Uploading" New topic
Author

File Uploading

Maryam Nouhnejad
Ranch Hand

Joined: Oct 04, 2006
Posts: 39
Hello everyone,

I'm writing a web photo gallery project & I should use file uploading in order to upload the photos somewhere in the server-side.
But I'm not sure exactly how I should do this. So far I have created a jsp file (SelectFile.jsp) & written this peice of code in that :

<form action=http://localhost:8200/FileUploading/Upload.jsp enctype="multipart/form-data" method="post">
<input type=file name=file_name>
<br>
<input type=submit value=upload>
</form>


In Upload.jsp I make a bean object using the class below (UploadTheFile.java) and call its method.


Here is that method :

public void doUpload(HttpServletRequest request) throws IOException
{

ImageWriter printW = new ImageWriter(new BufferedImage(new FileWriter("image")));

ServletInputStream in = request.getInputStream();

int i = in.read();

while(i!=-1)
{

printW.print( (char) i);

i = in.read();

}

printW.close();
}


thanks in advance,

Maryam
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Have a look at this entry in our servets faq.


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: File Uploading
 
Similar Threads
Save and retrive file from JSP into BLOB
How to read a input type file in servlet and display the contents of a file in servlet
Uploading images with jsp
upload file question
Inserting images in to the database