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
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
paul wheaton
Jeanne Boyarsky
Ron McLeod
Sheriffs:
Paul Clapham
Liutauras Vilda
Devaka Cooray
Saloon Keepers:
Tim Holloway
Roland Mueller
Bartenders:
Forum:
Struts
FileUploading in struts1.1
yogi maheshnath
Ranch Hand
Posts: 30
posted 15 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Hi,
I want to upload files on server and create directories dynamically according to unique client_name.Here is my code:-
public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) { DynaActionForm addForm = (DynaActionForm) form; String client_name=request.getParameter("client_name"); String project_name=request.getParameter("project_name"); String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort(); System.out.println(basePath); try { //Process the form file FormFile file= (FormFile) addForm.get("file"); String contentType=file.getContentType(); String fileName=file.getFileName(); byte[] fileData=file.getFileData(); String dir=client_name+"/"+project_name; String filePath=getServlet().getServletContext().getRealPath("/")+"upload"+"/"+dir; File file1=new File(dir); if(!file1.exists()) { file1.mkdirs(); } File file2=new File(filePath,fileName); if(!file2.exists()) { FileOutputStream fileOutStream=new FileOutputStream(file2); fileOutStream.write(fileData); fileOutStream.flush(); fileOutStream.close(); } //request.setAttribute("fileName",fileName); } catch(Exception e) { System.out.println("Exception:"+e.getMessage()); } return null; } }
Its Showing cannot find the sepecified path,as i want create directories in upload folder on my server.Please help to solve this.
Thanks&Regards<br />Yogi MaheshNath
David Newton
Author
Posts: 12617
I like...
posted 15 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
It'd be helpful to specify *when* you get the error.
If we don't do the shopping, we won't have anything for dinner. And I've invited this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
java.io.FileNotFoundException
JSP uploader
exception in uploading the file
Commons FileUpload
How to get upload an image on server and get it on next jsp?
More...