Internet Marketing Forums - Where Great Marketing Ideas Come to Life Internet Marketing Forums - Where Great Marketing Ideas Come to Life
Products
This is a revenue share forum
Can You Handle A Traffic Surge
Can You Handle A Traffic Surge?

It's Back, It's Meaner, It's Bigger, It's Better!

Super Promoter has provided marketers with numerous reponsive leads over the years.
Now the original Super Promoter is back with a vegeance.

Looking to reach to more leads than you can handle? You just found a big break.
Get yours now


Go Back   Internet Marketing Forums .Net > Internet Marketers' Products and Services > Programming / Scripts
User Name
Password
Register FAQ Members List Classifieds Blog Mark Forums Read

Notices

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 10-26-2009, 09:22 AM
arbaba's Avatar
Set Avatar
Banned
 
Join Date: Oct 2009
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
arbaba is on a distinguished road
Code for file upload in JSP

Use request object to upload file using JSP.
1.. make an html page from where u user input tag with file type..
this page should be only one input tag.... not more than one..
form tage should use encrype="multipart/form-data".
2.. then use this code... on JPS side....
this is my Bean... where i send request as parameter...
and FileServerPath is the target location.
3.. this method return false, if fails and enter the error
into ErrorMessage gloabal variable.




public boolean FileUploadProcess(javax.servlet.http.HttpServletRe quest
request,
String FileServerPath)
{
String contentType = request.getContentType();
if ((contentType != null) &&
(contentType.indexOf("multipart/form-data") >= 0))
{
try
{
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);
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());
//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;

String tmp_file = saveFile.toLowerCase();
if (tmp_file.equals(this._GIF) ||
tmp_file.equals(this._JPEG) ||
tmp_file.equals(this._JPG) || tmp_file.equals(this._PNG))
{
this.FileUserName = saveFile;
this.FileNewName = (new java.util.Date().getTime()) +
saveFile;
//System.out.println("File path = " +
FileServerPath+this.FileNewName);
FileOutputStream fileOut = new
FileOutputStream(FileServerPath +
this.FileNewName);

fileOut.write(dataBytes, startPos, (endPos - startPos));
fileOut.flush();
fileOut.close();
return true;
}
else
{
this.ErrorMessage = "Invalid File Format. " +
"File Format should be .png, .gif,
.jpg or .jpeg.";
return false;
}
}
catch (Exception exception)
{
this.ErrorMessage = exception.getMessage();
return false;
}
}
else
{
this.ErrorMessage = "Ilegal ENCTYPE : must be
multipart/form-data\n" +
"ENCTYPE set = " + contentType;
return false;

}
}



bratz baby fish tank
Photos Tutorial

Last edited by arbaba; 11-04-2009 at 03:02 PM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



Similar Threads
Thread Thread Starter Forum Replies Last Post
Code for file upload in PHP arbaba Programming / Scripts 0 10-26-2009 09:21 AM
photo and video upload + viewing on website mautay Web and Graphic Design 3 04-12-2009 04:50 AM
Possible code error in this banner simonsayzzz Markerters Lounge 0 01-28-2009 08:41 AM



All times are GMT -5. The time now is 08:38 PM.



Powered by vBulletin® Version 3.8.2
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.1.0
Internet Marketing ForumsAd Management by RedTyger

Internet Marketing News | Prospect Response
Hosted By Server Yard

Internet Marketing Forums - Bringing Internet Marketing Ideas to Reality Internet Marketing Forums - Bringing Internet Marketing Ideas to Reality Internet Marketing Forums - Bringing Internet Marketing Ideas to Reality

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19