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 Fileupload

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

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

in the page upload_page.jsp
its showing error on line 20
can nayone help me out of this!

Posted by rafia on Sunday, 08.22.10 @ 08:47am | #99087

My heartful thanks for the above code which is perfectly working..

Posted by fathima on Monday, 06.14.10 @ 12:57pm | #97570

pls help me get the process of displaying this pictures that i am uploading on a web page.

Posted by michael okwe on Wednesday, 03.31.10 @ 00:14am | #95986

why this has show error after i copy and paste into dreamveawer after execute it?
It shown error like this:
type Exception report

message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

org.apache.jasper.JasperException: An exception occurred processing JSP page /upload_page.jsp at line 21


what problems with this???
how to solve it???
can answer me asap??thanks..

Posted by Janice on Sunday, 03.28.10 @ 09:28am | #95918

Thank you Rose India for providing such significant suggstions.

Posted by Kranthi on Thursday, 03.4.10 @ 16:30pm | #95299

when i use this code i am getting the error.. java.lang.StringIndexOutOfBoundsException: String index out of range: -1208

will the code work even for other file types like images??

Posted by satishlagi on Sunday, 11.8.09 @ 12:38pm | #92420

how to fit this >>>>>

#1289 - The 'InnoDB' feature is disabled; you need MySQL built with 'InnoDB' to have it working

Posted by skaworld on Monday, 08.17.09 @ 17:14pm | #90077

hello ,
hi this code is executed only for files .txt i can't upload foles .docs ...
thank's

Posted by hamza on Friday, 07.31.09 @ 04:50am | #89723

i found this site is best site for java tutorials..

Posted by ambar on Saturday, 07.4.09 @ 11:49am | #89030

how can I change download directory.I want to save the upload files in a different directory...

Posted by Visitor on Friday, 05.29.09 @ 00:35am | #88108

i try run this code using my database:

<%@ page import="java.io.*,java.sql.*,java.util.*,java.text.*,java.text.SimpleDateFormat" %>
<html>
<%
int val =0;
String contentType = request.getContentType();
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);
System.out.println("saveFile=" + saveFile);
saveFile = saveFile.substring(saveFile.lastIndexOf("\\")+ 1,saveFile.indexOf("\""));
System.out.println("saveFile" + saveFile);
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,contentType.length());
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;

FileOutputStream fileOut = new FileOutputStream(saveFile);
fileOut.write(dataBytes, startPos, (endPos - startPos));
%>

<%
Connection con=null;
PreparedStatement pstatement = null;
String line = null;
String value=null;
String url = "jdbc:mysql://localhost:3306/";
String dbName = "file_upload";
String driver = "com.mysql.jdbc.Driver";
String userName = "root";
String password = "root";
try{
StringBuilder contents = new StringBuilder();
BufferedReader input = new BufferedReader(new FileReader(saveFile));
while (( line = input.readLine()) != null){
contents.append(line);
}
value = contents.toString();
System.out.println("Value:"+value);
Class.forName("com.mysql.jdbc.Driver");
con = DriverManager.getConnection(url+dbName,userName,password);
java.util.Date now = new java.util.Date();
String DATE_FORMAT = "yyyy-MM-dd hh:mm:ss";
SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT);
String strDateNew = sdf.format(now) ;

String queryString = "INSERT INTO file_tbl set file_data='"+value+"',file_date='"+strDateNew+"'";

//out.println(queryString);

pstatement=con.prepareStatement(queryString);


val = pstatement.executeUpdate();

if(val>0)
{
%>
<br><br>
<b>File <% out.println(saveFile); %> has been uploaded and inserted into Database at <%=strDateNew%>.</b>
<%
}


}
catch(Exception e)
{}
}
%>
</html>

why this error 'java.lang.StringIndexOutOfBoundsException: String index out of range' appear?It is related about my class or .properties had declared?

Posted by ef on Thursday, 05.21.09 @ 13:31pm | #87885

when i try to run this code at local host the error appear..Why this error appear?

org.apache.jasper.JasperException: String index out of range: -41011
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:372)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)


root cause

java.lang.StringIndexOutOfBoundsException: String index out of range: -41011
java.lang.String.substring(Unknown Source)

Posted by ef on Thursday, 05.21.09 @ 13:24pm | #87884

it's a good example.. but when i want to upload a file with .doc it will get error.. how to upload a file with document?

Posted by chel on Tuesday, 05.12.09 @ 15:10pm | #87627

i am is vary happy for getting this code

Posted by sri chaitanya on Friday, 04.17.09 @ 01:51am | #86873

suppose that i have such a form that includes the name , the model and the image of a car..

how could i get that data and file in server side and validate it..

i hope to find a helpful solution.
Kind Regards...

Posted by ADi on Tuesday, 03.24.09 @ 09:01am | #86162

Sir am not able to understand this code this code is working but nothing saving in database.

After clicking on submit button
blank page is showing.

please help me

Posted by Ashwin on Thursday, 02.26.09 @ 04:46am | #85244

How to create a chart dynamically from database using jsp

Posted by asw on Tuesday, 11.4.08 @ 08:55am | #81505

i want insert form data and upload a file at a time in to table . not individual

Posted by ramaswamy on Wednesday, 09.24.08 @ 17:49pm | #80664

how to upload any file like doc,jpg,png excel file from client to server.and save on server at that format

Posted by Rakesh on Saturday, 09.20.08 @ 06:43am | #80559

please tekll me code for uploading image from client to server.this tutorial is very good.

Posted by rakesh on Thursday, 09.11.08 @ 06:43am | #78625

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.