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



Home Answers Viewqa Struts struts image uploading
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


pruthvini H M
struts image uploading
0 Answer(s)      3 years and 8 months ago
Posted in : Struts


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

Advertisement
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
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
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 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 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.  
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
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 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
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
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
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 upload - Struts
image upload  Can any one help me how to upload an image using struts
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
Text preview on a Image - Struts
on just above my image.But my requirement is,it should display on the image.The image
 

 

 

DMCA.com