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 org.apache.struts.action.ActionForm;
import org.apache.struts.upload.FormFile;

public class FileUploadForm extends ActionForm{

     private FormFile theFile;

    public void setTheFile(FormFile theFile) {
        this.theFile = theFile;
    }

    public FormFile getTheFile() {
        return theFile;
    }

}

FileUploadAction:

   package com.action.form;

    import java.io.DataInputStream;
    import java.io.FileOutputStream;
    import java.io.IOException;
    import java.io.InputStream;

    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;

    import org.apache.struts.action.Action;
    import org.apache.struts.action.ActionForm;
    import org.apache.struts.action.ActionForward;
    import org.apache.struts.action.ActionMapping;
    import org.apache.struts.upload.FormFile;


    import java.io.*;
    import java.sql.*;

    public class FileUploadAction extends Action {
        public ActionForward execute(ActionMapping mapping,ActionForm form,HttpServletRequest request,HttpServletResponse response) throws Exception, IOException, SQLException{

            System.out.println("hhhhhhhhhhhhhhhhhh");

            //FormFile theFile=((FileUploadForm)form).getTheFile();

            System.out.println("IN FILE UPLOAD ACTION");
            FileUploadForm myForm=(FileUploadForm)form;
            FileOutputStream outputStream;
            try  {
                     FormFile myFile = myForm.getTheFile();
                     System.out.println(myFile);
                     byte[] fileData = myFile.getFileData();
                     System.out.println(fileData);
                             Class.forName("com.mysql.jdbc.Driver");
                          Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/alumni","root","root");
                          Statement st=con.createStatement();

                           //String path = getServlet().getServletContext().getRealPath("")+"/"+ formFile.getFileName();
                        outputStream = new FileOutputStream(new File(path));            
                     outputStream.write(FileUploadForm.getFileData());
                     } 

                 finally {
                         if (outputStream != null)   
                     {
                       outputStream.close();
                             }
                     }       

            return null;
           }
    }
View Answers









Related Tutorials/Questions & Answers:
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... links: http://www.roseindia.net/struts/strutsfileuploadandsave.shtml http
Advertisements
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... links: http://www.roseindia.net/struts/strutsfileuploadandsave.shtml http
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... links: http://www.roseindia.net/struts/strutsfileuploadandsave.shtml http
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
Struts file uploading - Struts
Struts file uploading   Hi all, My application I am uploading files using Struts FormFile. Below is the code. NewDocumentForm... when required. I could not use the Struts API FormFile since
uploading image in php - PHP
uploading image in php  I am looking for a PHP script to upload image into mysql database
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 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
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 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
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 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 code for scan the file while uploading - Struts
struts code for scan the file while uploading  Hi, I want the file to be scanned with anti-virus while uploading into server. can provide me help in this regard. Thanks in Advance.   For this you need third
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
Getting path name of uploading file in struts 2.1.8
Getting path name of uploading file in struts 2.1.8  In my question I used struts 2.8.1 instead of 2.1.8. Sorry
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 upload - Struts
image upload  Can any one help me how to upload an image using struts
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
Getting path name of uploading file in struts 2.8.1
Getting path name of uploading file in struts 2.8.1  Hai! I am using struts 2.8.1. I want to upload file into database with the path name. How can I can get the original path name of the file in struts 2.8.1? It only display
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 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  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
Text preview on a Image - Struts
on just above my image.But my requirement is,it should display on the image.The image
display the generated image from byte array - Struts
display the generated image from byte array  how to create image from byte array using struts and display it in struts html.please give me the sample code
Can i insert image into struts text field
Can i insert image into struts text field  please tell me can i insert image into text field
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
I want Image Album like -orkut and Facebook Using Struts 1.2
I want Image Album like -orkut and Facebook Using Struts 1.2  photo gallery Iam uploading images in the serverusing uploading program, now i need... facebook and orkut did.. Please suggest me.... How to store the link of a image
create a form using struts
create a form using struts  How can I create a form for inputting text and uploading image using struts
i want image upload and download useing STRUTS 1.2 version example..
i want image upload and download useing STRUTS 1.2 version example..  i am fresher of the developer..i want code for above title topic(i want image upload and download useing STRUTS 1.2 version example..)..plz send me code for my
struts
struts  Hi,... please help me out how to store image in database(mysql) using struts
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
need dynamic image example
need dynamic image example  struts 2 img example for a dynamic image.... I am creating a profile for a user and the user is uploading his image which I... this with the image. I need to see an example of how to do this for an image. I am
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
STRUTS
STRUTS  MAIN DIFFERENCES BETWEEN STRUTS 1 AND STRUTS 2
Struts
Struts   How to retrive data from database by using Struts
STRUTS
STRUTS  MAIN DIFFERENCES BETWEEN STRUTS 1 AND STRUTS 2
Struts
Struts  what is SwitchAction in struts
Struts
Struts  how to learn struts

Ads