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



Home Answers Viewqa JSP-Servlet Uploading an image

Have Programming Question? Ask it here!
 
 
 


Jagadeesh
Uploading an image
2 Answer(s)      5 years and 8 months ago
Posted in : JSP-Servlet



Advertisement
View Answers

December 28, 2008 at 9:57 PM


Hi friend,

Code to help in solving the problem :
<html>
<head><title>Upload page</title></head></p> <p><body>
<form action="employee_upload_profile_image.jsp" method="post" enctype
="multipart/form-data" name="form1" id="form1">
<center>
<table border="2">
<tr>
<td align="right"><b>Employee Name:</td>
<td ><input type="text" name="emp_name"></td>
</tr>
<tr>
<td align="right"><b>Employee Address:</td>
<td ><input type="text" name="address1"></td>


</tr>
<tr>
<td>
</td>
<td>
<input type="text" name="address2">
</td>
</tr>
<tr>
<td align="right"><b>Contact Number:</td>
<td ><input type="text" name="contact_number"></td>
</tr>
<tr>
<td align="right"><b>Employee Email ID:</td>
<td ><input type="text" name="email_id"></td>
</tr>


<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>



December 28, 2008 at 9:58 PM


"employee_upload_profile_image.jsp"

<%@ page import="java.util.List" %>
<%@ page import="java.util.Iterator" %>
<%@ page import="java.io.File" %>
<%@ page import="org.apache.commons.fileupload.servlet.ServletFileUpload"%>
<%@ page import="org.apache.commons.fileupload.disk.DiskFileItemFactory"%>
<%@ page import="org.apache.commons.fileupload.*"%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>


<center><h1>Your Profile has been Uploaded</h1></center>
<%!
String emp_name="";
String emp_c_number="";
String emp_emailid="";
String address1="";
String address2="";
int count1=0,count2=0,count3=0,count4=0,count5=0;
%>
<%
boolean isMultipart = ServletFileUpload.isMultipartContent(request);
if (!isMultipart) {
} else {
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();
if (item.isFormField())
{
String name = item.getFieldName();
String value = item.getString();
if(name.equals("emp_name"))
{
emp_name=value;
count1=1;
}
if(name.equals("address1"))
{
address1=value;
count2=2;
}
if(name.equals("address2"))
{
address2=value;
count5=5;
}
if(name.equals("contact_number"))
{
emp_c_number=value;
count3=3;
}


if(name.equals("email_id"))
{
count4=4;
emp_emailid=value;
}





} else
{
try {


String itemName = item.getName();
File savedFile = new File(config.getServletContext().getRealPath("/")
+"emp_image\\image\\"+itemName);
item.write(savedFile);
%><center></table><table ><tr><td width="210"></td><td> <img border="2"
src=image/<%=itemName %> width="137" height="140"></td></tr></table><table
border="2" width="350">


<% if(count1==1)
out.println("<tr><td align='left'><b>Name:</td><td><b>"+emp_name);
if(count2==2)
out.println("</td><tr><td align='left'><b>Addresss:</td>
<td><b>"+address1);
if(count5==5)
out.println("</td><tr><td align='left'><b></td><td><b>"+
address2);
if(count3==3)
out.println("</td><tr><td align='left'><b>Contact No</td>
<td><b>"+emp_c_number);
if(count4==4)
out.println("</td><tr><td align='left'><b>Email ID
</td><td><b>"+emp_emailid);
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
%>
</td></tr></table></center>
Thanks


Related Tutorials/Questions & Answers:
Image uploading
Image uploading  Hi,can anyone explain the following code. The code related to uploading an image file to oracle database using java servlet. CODE import java.io.*; import java.io.IOException; import
uploading image in php - PHP
uploading image in php  I am looking for a PHP script to upload image into mysql database
Advertisements
Image uploading in FTP Server
Image uploading in FTP Server  I want to upload images to a ftp server every 1 hour automatically using java..please help
uploading image in the form
uploading image in the form  Hi All, I am working to build a form like railway registration form which accepts user id and password and image for authentication. And i want all users should be able to see the image once
change the name of the image after uploading the image
change the name of the image after uploading the image   my form consists of a textbox and uploading the image.after uploading the image i want to change the name of the image with the content of the textbox before saving
Uploading an image - JSP-Servlet
Uploading an image  I am doing a jsp project. In this uploading an image is a part. For that i had done a coding for uploading... and uploading is done by different jsp coding. I don't know how to code for file size
Uploading Multiple Image On Server?
Uploading Multiple Image On Server?  Hello sir, I am stuck with a problem of uploading multiple images on server. i have done a code which works fine for uploading single image,but it doesn't work with uploading multiple
Uploading image using jsp
Uploading image using jsp  how to upload image using jsp. Already i tried, But that image file does not read. It returns only -1 without reading that image file ... I want know that solution using by u... Thanks, P.S.N.  
struts image uploading
struts image uploading  please let me know how to upload image in database using struts ..i have written form class and 'm hanging out in action class .... form FileUploadForm: package com.action.form; import
struts image uploading
struts image uploading  please let me know how to upload image in database using struts ..i have written form class and 'm hanging out in action class .... form FileUploadForm: package com.action.form; import
struts image uploading
struts image uploading  please let me know how to upload image in database using struts ..i have written form class and 'm hanging out in action class .... form FileUploadForm: package com.action.form; import
struts image uploading
struts image uploading  please let me know how to upload image in database using struts ..i have written form class and 'm hanging out in action class .... form FileUploadForm: package com.action.form; import
Uploading an image into the table - JSP-Servlet
Uploading an image into the table  how to upload an image... binary stream of given image. FileInputStream fis; try { // Load JDBC..."); // create a file object for image by specifying full path of image
Problem in uploading image to to mysql database
Problem in uploading image to to mysql database  Hi, need some help here, i have a program where a user can input name, city and upload image. when a user click the submit button the name, city and the image(Save as BLOB) must
Problem in uploading image to to mysql database
Problem in uploading image to to mysql database  Hi, need some help here, i have a program where a user can input name, city and upload image. when a user click the submit button the name, city and the image(Save as BLOB) must
save the uploading image with user specified name
save the uploading image with user specified name  My form consists of a textbox and an upload image with submit button.When i submit the form I want to save the uploaded image in a folder with user specfied name
save the uploading image with user specified name
save the uploading image with user specified name  My form consists of a textbox and an upload image with submit button.When i submit the form I want to save the uploaded image in a folder with user specfied name
Uploading a Profile with image[file] into a sql database
Uploading a Profile with image[file] into a sql database  I need to upload a file along with the some text into a database ......[ Similar to http://www.roseindia.net/jsp/jspfileupload/employeeuploadprofile_image.shtml
uploading of image showing exception when size increases.
uploading of image showing exception when size increases.  Hi . I have a project in which the user can upload images. it works properly, but when the image size increases to arnd 1 MB or more it shows exception. I am using tomcat
image uploading perminssion in server - JSP-Servlet
image uploading perminssion in server  thanks dear, but i am working in Linux Ubuntu, how can i set the path in server. my problem is i am not able to access the folders wherever we are uploading the files, we are not able
image uploading perminssion in server - JSP-Servlet
image uploading perminssion in server  Dear All, I am facing some problem image uploading in server that i working fine in my system, OS Ubuntu. but in server it is showing following error
image uploading perminssion in server - JSP-Servlet
image uploading perminssion in server  Thanks deepak following my... to writing image file in this path.. in multipartRequest. if u have any other uploading script please help me.. thanks   Hi, Plz give
image uploading perminssion in server - JSP-Servlet
image uploading perminssion in server  dear friend... following is my uploading code and i want to save some records....... while submitting time i am getting following error.................. HTTP
Need help in image uploading - JSP-Servlet
Need help in image uploading  hii, i have one doubt in uploading an image in jsp. I want to display image from DB to my jsp page. For that i... to remote server..??? regards Sreejith Here is my code for image uploading
error in uploading image from jsp to oracle 10g database
error in uploading image from jsp to oracle 10g database  ... try to insert into the image into the database i got the above error please advice how to get rid of error   JSP upload image in Mysql database
Using a image for Browse button instead of normal html Browse button for Uploading files from a JSP - JSP-Servlet
. Is it not possible to use a image instead of normal html Browse button for uploading files...Using a image for Browse button instead of normal html Browse button for Uploading files from a JSP  I am using the following code snippet
rename before uploading
rename before uploading  I need to change (rename)the file name/image name before uploading it so that the file gets uploaded on server with this new name
Uploading files
Uploading files  Hi, Please provide html code for my question. I need to insert the browsed files temporarily to text area while attaching more than one files during mailing
photo uploading
photo uploading  i want the code upload the image in oracle database
uploading a file
uploading a file  When I am trying to upload a file to another system in lan at a location "http://192.168.12.5:8080/tomcat-docs/myapps",then it is giving the following error message "http://192.168.12.5:8080/tomcat-docs/myapps
uploading problem
uploading problem  i use glassfish server.. using netbeans for jsp... i wnat to upload a file to a folder 'doc' and insert corresponding data... curresponding image files start new upload"); %><
uploading audio file iphone
uploading audio file iphone  uploading audio file iphone
uploading and reading the excel daa
uploading and reading the excel daa  uploading the excel file not getting the data of the excel
Uploading File on Server
Uploading File on Server  Hello, Can someone explain or suggest example. How do i uploading files on the FTP Server. Thanks
image
image  how to add the image in servlet code
Uploading website
Uploading your website       Uploading Web Site After developing the web... file you can use mput command. 7) After uploading you web site
Image
Image  how to insert image in xsl without using xml. the image was displayed in pdf..Please help me
Image
Image  how to insert image in xsl without using xml. the image was displayed in pdf..Please help me
Image
Image  how to insert image in xsl without using xml. the image was displayed in pdf..Please help me
Uploading a Software and storing in the database
Uploading a Software and storing in the database  I want to upload.... The coding present in the site for uploading and storing in the database... me with the code for uploading software of bigger size
uploading file to tomcat server
uploading file to tomcat server  please tell me how to upload a file to the URL "http://192.168.12.7:8000/tomcat-docs/" ? thanks
uploading and copying files
uploading and copying files  how can i upload and copy one file based on the given inputs and copy it from one directory to another
FORM Tag Correctly for Uploading Files.
FORM Tag Correctly for Uploading Files.  How To Write the FORM Tag Correctly for Uploading Files?   Hi friends, When you clicks the submit... from the browser to the Web server. This transferring (uploading) process
File uploading - Ajax
File uploading  hi friends, how to uploading the file by using "AJAX".Please send the complete source code for this application   where u want to store the file Can u specify
Uploading a file using UploadBean
Uploading a file using UploadBean  Dear sir, In my project i have to upload the file and use the same file for getting a values from that uploaded .xls file.I used UploadBean for uploading .For the first time when i
query related to uploading file
query related to uploading file  hello friends i am doing my project in servlet and i want to upload a file and store file in local hard drive... to save the uploading time and date in database. please help me it is urgent
Uploading Employee Profile with image
Uploading Employee Profile with image  ... a image in the employee file. In this example we are going to tell you how we can upload image in a file by using Jsp and how they will get stored
Uploading Employee Profile with image
Uploading Employee Profile with image  ... a image in the employee file. In this example we are going to tell you how we can upload image in a file by using Jsp and how they will get stored
Struts file uploading - Struts
Struts file uploading   Hi all, My application I am uploading files using Struts FormFile. Below is the code. NewDocumentForm... it is breaking while uploading the large file. Please let me know if you know any API
excel uploading in jsp
excel uploading in jsp  could you provide the source code for: 1)have to upload an empty excel sheet at client side i.e if client clicks an excel icon an empty excel sheet should open 2)when they fill data in that sheet and click
 

 

 

DMCA.com