File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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 Soft Skills this week in the Jobs Discussion 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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: File Uploading