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 uploadingstruts 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 uploadingstruts 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 uploadingstruts 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 uploadingstruts 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 uploadingImage 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 - StrutsStruts 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
Image uploading in FTP ServerImage 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 imagechange 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 formuploading 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-ServletUploading 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 jspUploading 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-ServletUploading 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 databaseProblem 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 databaseProblem 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 namesave 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 namesave 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 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-Servletimage 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.1Getting 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
Need help in image uploading - JSP-ServletNeed 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 strutsstruts Hi,... please help me out how to store
image in database(mysql) using
struts rename before uploadingrename 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 filesUploading 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 uploadingphoto uploading i want the code upload the
image in oracle database
need dynamic image exampleneed 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 fileuploading 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 problemuploading 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");
%><
STRUTSSTRUTS MAIN DIFFERENCES BETWEEN
STRUTS 1 AND
STRUTS 2
Struts Struts How to retrive data from database by using
Struts STRUTSSTRUTS MAIN DIFFERENCES BETWEEN
STRUTS 1 AND
STRUTS 2
StrutsStruts what is SwitchAction in
struts StrutsStruts how to learn
struts