Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Spring Framework | Web Services | BioInformatics | Java Server Faces | Jboss 3.0 tutorial | Hibernate 3.0 | XML

Tutorial Categories: Ajax | Articles | JSP | Bioinformatics | Database | Free Books | Hibernate | J2EE | J2ME | Java | JavaScript | JDBC | JMS | Linux | MS Technology | PHP | RMI | Web-Services | Servlets | Struts | UML


Java Tutorials



Struts Tutorials

Struts Resources

Visit Forum! Post Questions!
Jobs At RoseIndia.net!

Jsp File_upload Index

User Comments
Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl
  Blink   Furl   Simpy   Y! MyWeb 

Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 

Current Comments

10 comments so far (post your own) View All Comments Latest 10 Comments:

this example is working file in windows env.but the same code if i am trying run in linux,file is creating but size is zero and in browser it is giving index out of bound exception it is giving pls let me wht changes i need to do.

Posted by gupta on Wednesday, 06.16.10 @ 15:06pm | #97619

I am getting an error..as mentioned..
org.apache.jasper.JasperException: Unable to compile class for JSP

An error occurred at line: 2 in the jsp file: /single_upload_page.jsp
Generated servlet error:
String literal is not properly closed by a double-quote


error is coming in the following jsp page...
<%@ page import="java.io.*" %>
String contentType = request.getContentType();
if ((contentType != null) && (contentType.indexOf("multipart/
form-data") >= 0)) {
DataInputStream in = new DataInputStream(request.
int formDataLength = request.getContentLength();
byte dataBytes[] = new byte[formDataLength];
int byteRead = 0;
int totalBytesRead = 0;
while (totalBytesRead < formDataLength) {
byteRead = in.read(dataBytes, totalBytesRead,
totalBytesRead += byteRead;
String file = new String(dataBytes);

String saveFile = file.substring(file.indexOf("filename=\
"") + 10);
saveFile = saveFile.substring(0, saveFile.indexOf("\n"));
saveFile = saveFile.substring(saveFile.lastIndexOf("\\")
+ 1,saveFile.indexOf("\""));
int lastIndex = contentType.lastIndexOf("=");
String boundary = contentType.substring(lastIndex + 1,
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))
FileOutputStream fileOut = new FileOutputStream(saveFile);
fileOut.write(dataBytes, startPos, (endPos - startPos));
<Br><table border="2"><tr><td><b>You have successfully
upload the file by the name of:</b>
<% out.println(saveFile); %></td></tr></table>

plzzzzz help me out..

Posted by harshal on Friday, 05.7.10 @ 11:28am | #96881

that is very simple and easy script

Posted by rahul on Friday, 02.5.10 @ 08:57am | #94595

your tutorials is exactly what i needed ....its very clear and understandable...great work...

Posted by siddharth on Thursday, 08.20.09 @ 19:43pm | #90185

this code is working in uploading files but when we open file by a href tag. source file not found appear.
and if I run main project again then file open.
I need solution for it urgently please give any solution...

Posted by vikas singhal on Friday, 06.26.09 @ 13:45pm | #88818

okay. Its really good.

Posted by Elumalai on Friday, 03.27.09 @ 22:31pm | #86293

Hello, how do I fix the bug in Internet Explorer to perform upload?

Posted by TriploX on Thursday, 01.1.09 @ 04:35am | #83374

Thaks for the tutorial just wondering to which location is the file uploaded?

If its uploaded to memory how can we save it on disk?

Posted by pavan on Thursday, 12.4.08 @ 14:02pm | #82403

NIce Real working Code. Not like other who claims & it failures undercertain circumstances.
I Use almost all pkgs to do a upload (txt based file). but failure some where invoker Servlet prob or some servlet listenr classes not found.
But really this astonishingly upload any means any type of file. whether it is a pdf , or doc or even excel sheets
even if i tried an winzip software installer, exactly it uploads & evn starts installing from the directory where u uploaded it.
Thanks to rose india

Posted by sushanta on Tuesday, 11.25.08 @ 05:47am | #82012

Tutirial is very easy to understand but
I am gettign on error. Pls help me
ava.io.FileNotFoundException: D:\Musicworld\out\exploded\MusicworldWeb\uploadedFiles\D:\Others\Photo\9-08-2008\J1.jpg (The filename, directory name, or volume label syntax is incorrect)
at java.io.FileOutputStream.open(Native Method)
at java.io.FileOutputStream.<init>(FileOutputStream.java:179)
at java.io.FileOutputStream.<init>(FileOutputStream.java:131)
at org.apache.commons.fileupload.disk.DiskFileItem.write(DiskFileItem.java:439)
at org.apache.jsp.upload2_jsp._jspService(upload2_jsp.java:91)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:374)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:337)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)

Posted by Narayan on Tuesday, 09.23.08 @ 15:09pm | #80630

Ask programming questions?



Back to Tutorial


  JDO Tutorials
  EAI Articles
  Struts Tutorials
  Java Tutorials
  Java Certification

Tell A Friend
Your Friend Name


Browse all Java Tutorials
Java JSP Struts Servlets Hibernate XML
Ajax JDBC EJB MySQL JavaScript JSF
Maven2 Tutorial JEE5 Tutorial Java Threading Tutorial Photoshop Tutorials Linux Technology
Technology Revolutions Eclipse Spring Tutorial Bioinformatics Tutorials Tools SQL

Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs

About Us | Advertising On RoseIndia.net  | Site Map

India News

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright 2007. All rights reserved.