Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Struts
Search Coderanch
Advance search
Google search
Register / Login
Win a copy of
OCP Oracle Certified Professional Java SE 21 Developer Study Guide: Exam 1Z0-830
this week in the
Programmer Certification
forum!
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Campbell Ritchie
Tim Cooke
Liutauras Vilda
Jeanne Boyarsky
paul wheaton
Sheriffs:
Ron McLeod
Devaka Cooray
Henry Wong
Saloon Keepers:
Tim Holloway
Stephan van Hulst
Carey Brown
Tim Moores
Mikalai Zaikin
Bartenders:
Frits Walraven
Forum:
Struts
HOw to store image in struts?upload.FormFile
Satyajeet Kadam
Ranch Hand
Posts: 224
posted 17 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
HOw to store image in
struts
in contextfolder after uploading ?
package roseindia.net; 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 java.io.*; import javax.imageio.*; import org.apache.struts.upload.FormFile; import org.omg.CORBA.portable.InputStream; /** * @author Deepak Kumar * @Web <a href="http://www.roseindia.net" target="_blank" rel="nofollow">http://www.roseindia.net</a> * @Email roseindia_net@yahoo.com */ /** * Struts File Upload Action Form. * */ public class StrutsUploadAction extends Action { public ActionForward execute( ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception{ StrutsUploadForm myForm = (StrutsUploadForm)form; String path=request.getContextPath(); // Process the FormFile FormFile myFile = myForm.getTheFile(); String contentType = myFile.getContentType(); String fileName = myFile.getFileName(); int fileSize = myFile.getFileSize(); byte[] fileData = myFile.getFileData(); System.out.println("contentType: " + contentType); System.out.println("File Name: " + fileName); System.out.println("File Size: " + fileSize); return mapping.findForward("success"); } }
Milan Jagatiya
Ranch Hand
Posts: 164
posted 17 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
use IO ....
FormFile ff = upFileForm.getMyFile(); FileOutputStream fout = new FileOutputStream("dirpath"+ ff.getFileName()); InputStream in = ff.getInputStream(); BufferedReader br = new BufferedReader(new InputStreamReader(in)); String line; while ((line = br.readLine()) != null) { byte b[] = line.getBytes(); fout.write(b); }
enjoyyyy...
if you think brussel sprouts are yummy, you should try any other food. And this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
File type and size
How to store image file in specific folder
Why my action class in not executing?
Problem with file separator
Map the action form object
More...