image file upload to a web server

image file upload to a web server

Refer roseindia post http://www.roseindia.net/jsp/fileupload/Sinleupload.xhtml.shtml.

It works fine on my local computer. But when I use it on a server it don't work. My server uses Apache Tomcat 5 server. How can I upload a file to the web server?

View Answers

June 11, 2012 at 3:15 PM

Here is an example of uploading an image on the server. The user can browse the image and upload it on the server.

1)page.jsp:

<%@ page language="java" %>
<HTML>
<HEAD><TITLE>Display file upload form</TITLE></HEAD>

<BODY> <FORM ENCTYPE="multipart/form-data" ACTION=
"upload.jsp" METHOD=POST>
<br><br><br>
<center>
<table border="0" bgcolor=#ccFDDEE>
<tr>
<center>
<td colspan="2" align="center"><B>UPLOAD THE FILE</B><center></td>
</tr>
<tr>
<td colspan="2" align="center">&nbsp;</td>
</tr>
<tr>
<td><b>Choose the file To Upload:</b></td>
<td><INPUT NAME="file" TYPE="file"></td>
</tr>
<tr>
<td colspan="2" align="center">&nbsp;</td>
</tr>
<tr>
<td colspan="2" align="center"><input type="submit" value="Send File"> </td>
</tr>
<table>
</center>
</FORM>
</BODY>
</HTML>

2)upload.jsp:

<%@ page import="java.io.*" %>
<%@ page import="java.sql.*" %>

<% 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);
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));
fileOut.flush();
fileOut.close();
%><Br><table border="2"><tr><td><b>You have successfully upload the file by the name of:</b>
<% out.println(saveFile);%></td></tr></table>
<%
}
%>









Related Tutorials/Questions & Answers:
image file upload to a web server
image file upload to a web server  Refer roseindia post http... Tomcat 5 server. How can I upload a file to the web server?   Here is an example of uploading an image on the server. The user can browse the image
To scan a image and upload to server
To scan a image and upload to server  I am beginner of JavaME I want a code to scan a image and upload to server
Advertisements
scan a image and upload to server
scan a image and upload to server  Hai i am beginner of Java ME..I want the code To scan a image and upload to server
Capture a image and upload to server
Capture a image and upload to server  Hai team i have trouble to capture a image and upload to server in java me........... So i want a code immediately,.......To capture a image and upload to server in j2me...... If you give
scan a image and upload to server
and upload to server..after capture that image decoded it going to be convert digit value....My client want to scan a image and upload to server in j2me please refer me,to send a code for to scan a image and upload to server in j2me Thanks
Image upload file - JSP-Servlet
Image upload file  I want a code for image upload jsp or servlet.  Hi friend, For image upload jsp or servlet visit to : http://www.roseindia.net/jsp/file_upload/employee_upload_profile_image.shtml http
Upload image to the server in J2ME?
Upload image to the server in J2ME?  HI Team, I am new to the j2me and now I am working on the program that, upload captured image to the server by using j2me. I did this by using simulator but when I made hit from the mobile
jsp upload file to server
jsp upload file to server  How to create and upload file to server in JSP?   Find the given example that explains how to upload single and multiple file on server using JSP
How to upload file on FTP Server
How to upload file on FTP Server  In my application there is a requirement of uploading the file on FTP server. How to upload file on FTP Server... is good and can be used in Java applications. Read FTP File Upload in Java for more
upload file to server and store recode in database
upload file to server and store recode in database  i want to upload a file into the server and store a recode in mysql database.any one know the code
How display a Image on servlet from file upload - JSP-Servlet
How display a Image on servlet from file upload  Dear Sir, I were ask a question that How display the Image on servlet through file upload. Today I...; Hi friend, I am sending running code. Image upload page
How display a image on servlet from file upload - JSP-Servlet
How display a image on servlet from file upload   Dear Sir, My Question is: How display a image on servlet from file upload Your Answer: Hi... that an attempt to open the file denoted by a specified pathname has failed
File Upload
File Upload  when i execute the image upload to mysql database it shows an exception that file path cannot be found
image upload
image upload  Hello sir I want to upload image or any other type... be upload in the server and their path should be stored in database either in oracle or my sql. kindly help me.   JSP Upload file and save file path
upload an image
upload an image  Hello, i would like to upload an image to the database. how can i do it? what field type should i set in the database? thanx
upload image
upload image  I want to upload image from user using Jdbc connectivity and servlets and Html pages. I tried code but getting error using multi parts,so please send the code
Upload image
Upload image  Hai i beginner of Java ME i want code to capture QR Code image and send to the server and display value in Mobile Screen i want code in Java ME .java extension.. Regards senthil   To capture an image
Upload image
for to capture image and upload to server. Here i taken a snap but when am going to upload to server it shows decoding failed...How can i clear that bug.please help me.  Jsp Upload Image 1)page.jsp: <%@ page language="java
How display a image on servlet from file upload - JSP-Servlet
How display a image on servlet from file upload  Dear Sir, My issue is: How display a image on servlet from file upload I receive your answer today... upload page Employee Image
How display a Image on Servlet from file upload - JSP-Servlet
How display a Image on Servlet from file upload  Dear Sir, My requirement is I want to display a Image on Servlet from File Upload...); // Create a new file upload handler System.out.println(isMultipart
How to upload image to server in j2me by multipart/form-data?
How to upload image to server in j2me by multipart/form-data?  Hi, I need upload data to java server from j2me 1.Two text messages and 3 capture...) at java.lang.Thread.run(Unknown Source) From J2me I am using code to upload image to server
upload image
upload image  how can i retreive image from mysql using jsp in netbeans.The image type is varchar with size 200.the image is uploaded succesfully.The... of image at the screen.The retreival and uplaod code is here.. i.upload.jsp
upload image data
upload image data  Hii Upload image dat in csv files
upload image data
upload image data  Hii Upload image dat in csv files
image upload in webapp/upload folder
image upload in webapp/upload folder  sir i want to store upload image in my project directory WebApp/Upload_image/ pls send the jsp servlet code when i upload the image one error found "system cannot found the specified path
upload a image
upload a image  sir,how can i upload a image into a specified folder...;&lt;HEAD>&lt;TITLE>Display file upload form to the user&lt...;&lt;tr>&lt;td>&lt;b>Choose the file To Upload:&lt
image upload
image upload  How to access image file from database using jsp?  ... rs=st.executeQuery("SELECT images FROM image WHERE id = 1"); if(rs.next...("image/jpeg"); while((size=sImage.read(bytearray))!= -1
How to upload zip file from android to server programmatically?????
How to upload zip file from android to server programmatically?????  hi , I want to upload zip file from android phone sdcard to server programmatically. So any one do this task in past so please share your experience with me
Upload and insert the file contents - Java Server Faces Questions
Upload and insert the file contents  I want to browse and upload 2 files on server and insert the values into table from JSP page. So i have to browse and upload CSV files using the browse and upload button. as soon as i
image upload - Struts
image upload  Can any one help me how to upload an image using struts
Text Editor Image upload
Text Editor Image upload   how to browse an image from text editor instead of giving url of particular image using javascript
Image Upload Error
Image Upload Error  hi, I created one education website in jsp....in my registration page image uploading option also i attached in real path...it's working well in local file....when i upload file in live Using FTP
struts2 upload image public_html
struts2 upload image public_html  How to upload images in public_html file in Struts 2 application. Thanks in advance
Upload file on server automatically on specific time - JSP-Servlet
Upload file on server automatically on specific time  Hi all, Is there any way to upload file on server on specific time automatically using java... only to upload a file? If java application running, which will be the best
upload image to database
upload image to database  i am try to upload image to MySql database using netbeans. when jsp execute it return no error. but also data does inserted in database. i am using blob datatype and preopared statement
hibernate image Upload
hibernate image Upload  Sir, I had posted question regarding upload image, th answer you had given is using SQL, but I am using Hibernate to insert data in the same table where I want to insert image. Plz hlp me. Thanks
Having problem with image upload....
Having problem with image upload....  I am uploading profile pictures... To Upload:</b></td> <td><INPUT NAME="file" TYPE="file">...;tr><td><b>You have successfully upload the file:</b> <
Ajax file upload
Ajax file upload  I am developing a application for image upload using ajax and servlet. The image should be converted in byte[] and must be saved in oracle databse as blob. After uploading the image it should be displayed
upload image in php
upload image in php  after select image,how to save it in a folder...; <td width="246"> <input type="hidden" name="MAX_FILE_SIZE" value="2000000"> <input name="userfile" type="file" id="userfile"> </td>
image upload in java
image upload in java  Hi, I am working with java. In my application i want to give facility to user to add and change image. I use open dialog box to select image, it will work properly i.e on button click open dialog is open
File Upload
File Upload  Hi I need script / string in PHP where I uploaded the file in html frontend and it should sent the uploaded file as attachment to my email address
file upload
file upload  how to recieve the uploaded file on the next jsp page for modification if its uploaded to the previous page using a from
file upload using spring - Spring
file upload using spring  How to upload a file in server using spring framework
File Upload in Struts.
File Upload in Struts.  How to do File Upload in Struts
file upload plugin in jquery
file upload plugin in jquery  file upload plugin in jquery   You can use the following code to use the JQuery plugin. $(document).ready...", onComplete: function(response){ alert( "server response
FTP Server : Upload file
This tutorial contains description of file uploading to the FTP server using java
File upload in JSP
File upload in JSP  hi! In my previous interview i got two questions which i could not answer regarding file upload and annotations. I want to know which is the best method can be used for file upload. Whether moving them
Java upload file to ftp
Java upload file to ftp  Hi, How to uploaded file to a ftp server.... View complete example at FTP File Upload in Java Thanks... that uploads files on FTP server. You have to use the Apache FTP client library
Multiple image upload using JSP
Multiple image upload using JSP  I have written a code to upload...; String user_image_dir = user_name; > > File sourceFile; >... uploaded files > to a 'Upload' directory in the web > app*/ >
scan a QRCode imageimage and upload to server
scan a QRCode imageimage and upload to server   Hai team i create a code for to scan a image and upload to server in j2me. but i have a trouble so please clarify that. i want some sample code for scan a image and upload to server

Ads