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