Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa JSP-Servlet How display a Image on Servlet from file upload
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


Vijay
How display a Image on Servlet from file upload
1 Answer(s)      5 years and 10 months ago
Posted in : JSP-Servlet



Advertisement
View Answers

December 15, 2008 at 1:29 AM


Hi friend,

Code to help in solving the problem :

"upload.html"

<html>
<head><title>Upload page</title></head></p> <p><body>
<form action="tmp" method="post" enctype="multipart/form-data" name="form1" id="form1">
<center>
<table border="2">


<tr>
<td align="right"><b>Employee Image </td>
<td>
<input name="file" type="file" id="file">
<td>
</tr>

<tr>
<td align="center">
<input type="submit" name="Submit" value="Submit"/>
<input type="reset" name="Reset" value="Reset"/>

</td>
</tr>
</table>
</center>
</form>
</body>
</html>

"UploadFile.java"

import java.sql.*;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.util.*;
import org.apache.commons.fileupload.servlet.ServletFileUpload;
import org.apache.commons.fileupload.disk.DiskFileItemFactory;
import org.apache.commons.fileupload.*;
import org.apache.commons.fileupload.disk.*;


public class UploadFile extends HttpServlet{
public void doPost(HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException{
response.setContentType("text/html");

PrintWriter out= response.getWriter();
Connection con=null;
String itemName="";
boolean fileUpload=false;
try{
boolean isMultipart = ServletFileUpload.isMultipartContent(request);
FileItemFactory factory = new DiskFileItemFactory();
ServletFileUpload upload = new ServletFileUpload(factory);
List items = null;
try {
items = upload.parseRequest(request);
} catch (FileUploadException e) {
e.printStackTrace();
}
Iterator itr = items.iterator();
while (itr.hasNext())
{
FileItem item = (FileItem) itr.next();
String name = item.getFieldName();
if(name.equals("file"))
{
itemName = item.getName();
File savedFile = new File(request.getRealPath("/")+"image\\"+itemName);
item.write(savedFile);
fileUpload=true;
}
}
if(fileUpload==true)
{
out.println("File has been uploaded successfully");
out.println("<html>");
out.println("<body>");
out.println("<table><tr><td width='210'></td><td> <img border=2 src=image/"+itemName.toString().trim()+" width=137 height=140></td></tr></table>");
out.println("</body>");
out.println("</html>");
}

}
catch (Exception e){
e.printStackTrace();
}
}
}

web.xml:
<web-app>
<servlet>
<servlet-name>one</servlet-name>
<servlet-class>UploadFile</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>one</servlet-name>
<url-pattern>/tmp</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>Home.html</welcome-file>
</welcome-file-list>
</web-app>

For more information on Servlet visit to :

http://www.roseindia.net/servlets/

Thanks


Related Tutorials/Questions & Answers:
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... reason is inaccessible Thanks Sir, But Servlet page nothing display any type
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 get your answer. But Sir, It code not display the image on servlet
Advertisements
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. But It not display on servlet,Its appear a downloaded form and downloaded on disk when click
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
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
how to upload a file of apk format in a folder from servlet
how to upload a file of apk format in a folder from servlet  How to upload a file of apk format to a folder from servlet, i am trying to do, its getting uploaded as .zip file and not apk file
how to upload image from jsp to mssql
how to upload image from jsp to mssql  hi there!!, i'm using jsp and servlet to upload images to the database. however i have difficulty in uploading... uplaodimage.java(servlet)   Here is a code that uploads any file through
how to upload image from jsp to mssql
how to upload image from jsp to mssql  hi there!!, i'm using jsp and servlet to upload images to the database. however i have difficulty in uploading..., uplaodimage.java(servlet)   Here is a code that uploads any file through
how to upload a file - JSP-Servlet
: Display file upload form to the user UPLOAD THE FILE   Choose the file To Upload:   2...how to upload a file  Dear sir, Give me some code
How to upload a large excel file - JSP-Servlet
How to upload a large excel file   Dear sir , How to upload a large excel file and how to read a that large excel file or how to get a each column values from that large excel file.For small file i am getting values
servlet file upload
servlet file upload  please tell me the complete code to upload a file on localhost using servlet
Retrview image from sqlserver2000 and display in jsp - JSP-Servlet
Retrview image from sqlserver2000 and display in jsp  How to retreview image from sqlserver2000 to jsp? pls give the solution i am using Tomcat 4 Database Server:SQLSERVER2000 pls give the full coding  Hi friend
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...;HTML> <HEAD><TITLE>Display file upload form</TITLE></HEAD>
how do i upload a file by using servlet or jsp?
how do i upload a file by using servlet or jsp?  hi plz tell me the write java code
how to display image from byte arry - Java Magazine
how to display image from byte arry  Hi.. How to display a image using byte array[] object , which have the image data in binary format. If it can be resolved , itz very helpful for me. Regards Rajesh
how to display image with listview
how to display image with listview  How can i display the list view with the related images from database
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
how to display image and text in single jsp page from the mysql database
how to display image and text in single jsp page from the mysql database  hello please help me to display the image and text in single jsp page from mysql database if have any reference code please send me Thanks in advance
how to display a table from database using servlet
how to display a table from database using servlet  how to display a table with values from servletpage   Hi Friend, Please go through the following link: http://roseindia.net/jsp/servlet-jsp-data-list.shtml Thanks
how to upload an image from a jsp page to a mysql database table using jsp
how to upload an image from a jsp page to a mysql database table using jsp  how to upload an image from a jsp page to a mysql database table using jspstrong text
image display - JSP-Servlet
image display  how to display image that store in mysql database... column have BLOB datatype....  Hi Friend, Please visit the following link: http://www.roseindia.net/jsp/retrieve-image.shtml Thanks
how to display data from jsp file into database
how to display data from jsp file into database  this is a jsp file . look at the line with code-> Statement st=con.createStatement(); in the below example. the error is "cannot convert from java.sql.Statement
image upload with jsp from form
image upload with jsp from form  hi i used the code specified in your...-upload-and-stored-in-database.html but i am getting following error...) org.apache.jsp.upload_jsp._jspService(upload_jsp.java:85
File upload - JSP-Servlet
----------------------------------------------------------------------------- Display file upload form to the user <...File upload  I am trying to do a file upload program. But, it shows... the file To Upload
Upload Image to Database through Servlet - JSP-Servlet
Upload Image to Database through Servlet  Hello, I make a application from where I upload the Image from local disk then store in DB.Before storing... isMultipart = FileUpload.isMultipartContent(req); // Create a new file upload
How to read and display data from a .properties file from a jsp page
How to read and display data from a .properties file from a jsp page  I have a .properties file. I have to create a jsp page such that it reads the data from this .properties file and display it in table format. Ex:by using
File upload - JSP-Servlet
in the problem part]   Hi friend, Display file upload form to the user... to do a file upload part. For this, i designed two files one for input and other...(); %>You have successfully upload the file by the name
image upload and stored in database - JSP-Servlet
image upload and stored in database  How can i upload a image and store that image in a database
image upload and stored in database - JSP-Servlet
image upload and stored in database  How can i upload a image and store that image in a database
display multiple image file or pdf file in multiple column of a row from server or database
display multiple image file or pdf file in multiple column of a row from server... want to display that file to the user page but I want to display that file... uploading more files then uploaded file should be display again tow file in another row
passing the form values with image upload - JSP-Servlet
the request values from the fields rather than image . I want to know how can cut the values of other filds from the actual file that uploaded.Please give me... : 2. Enter value for field 2: 3. Upload file : and in your servlet you can
 

 

 

DMCA.com