struts image uploading

Ads
 

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

Ads









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
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 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.  
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
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
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
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  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
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
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
STRUTS
STRUTS  MAIN DIFFERENCES BETWEEN STRUTS 1 AND STRUTS 2
STRUTS
STRUTS  MAIN DIFFERENCES BETWEEN STRUTS 1 AND STRUTS 2
Struts
Struts  what is SwitchAction in struts
Struts
Struts  how to learn struts

Ads