This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Struts and the fly likes upload File and save into a directory Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "upload File and save into a directory" Watch "upload File and save into a directory" New topic
Author

upload File and save into a directory

Alessandro Ilardo
Ranch Hand

Joined: Dec 23, 2005
Posts: 218
Hi there,
I'm using FormFile to process uploads. Unfortunatly I can't write into the folder I want. I don't understand why it keeps tring to write under the bin directory where the application server (I suppose JVM) runs.

Can you please have a look and let me know where the mistake is.
(I'm using Struts 1.2.9 on JBoss 4.0.5)





11:38:35,383 DEBUG [AttachmentImplService] [saveFile] Ready to write on file system.
11:38:35,384 DEBUG [AttachmentImplService] [saveFile] System path is
/home/jboss/temp/

11:38:35,384 DEBUG [AttachmentImplService] [saveFile] File name is test_file.pdf
11:38:35,385 DEBUG [AttachmentImplService] [saveFile] Path is
/home/jboss/temp/
test_file.pdf
11:38:35,385 DEBUG [AttachmentImplService] [saveFile] Absolute path is /var/lib/jboss-4.0.5.GA/bin/
/home/jboss/temp/
test_file.pdf
11:38:35,386 WARN [AttachmentImplService] [saveFile] No sufficient privilege to read into this path.
11:38:35,386 WARN [AttachmentImplService] [saveFile] No sufficient privilege to read into this path.
11:38:35,387 ERROR [AttachmentImplService] [saveFile] No sufficient privilege to write into this path.
11:38:35,387 ERROR [AttachmentImplService] [saveFile] No sufficient privilege to write into this path.
11:38:35,388 WARN [RequestProcessor] Unhandled Exception thrown: class java.io.IOException
11:38:35,389 WARN [[action]] Servlet.service() for servlet action threw exception
java.io.IOException: [saveFile] No sufficient privilege to write into this path.
at it.federfarma.modena.web.service.press.AttachmentImplService.saveFile(AttachmentImplService.java:136)
at it.federfarma.modena.struts.action.press.PressDispatchAction.processAttachment(PressDispatchAction.java:304)
at it.federfarma.modena.struts.action.press.PressDispatchAction.create(PressDispatchAction.java:220)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.apache.struts.actions.DispatchAction.dispatchMethod(DispatchAction.java:270)
at org.apache.struts.actions.DispatchAction.execute(DispatchAction.java:187)
at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:431)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:236)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1196)
at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:432)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:175)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:524)
at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:74)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
at org.jboss.web.tomcat.tc5.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:156)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:869)
at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:664)
at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
at org.apache.tomcat.util.net.MasterSlaveWorkerThread.run(MasterSlaveWorkerThread.java:112)
at java.lang.Thread.run(Thread.java:595)

[ March 17, 2008: Message edited by: Alessandro Ilardo ]

trying to decode a woman mind....
Anirvan Majumdar
Ranch Hand

Joined: Feb 22, 2005
Posts: 261
Your problem lies in the line =>


The sysPath variable has a value which doesn't contain any root directory path. As a result your server is attempting to resolve a corresponding relative path, which points to a location under your webapp. This will not work since you cannot write any files under the webapp directories at run-time.

What you should try is setting your sysPath variable to an absolute path which starts from an existing drive's root. (Like "c:/" in Windows)
Alessandro Ilardo
Ranch Hand

Joined: Dec 23, 2005
Posts: 218
To me, it does:


11:38:35,384 DEBUG [AttachmentImplService] [saveFile] System path is
/home/jboss/temp/

(I'm working under unix)
Anirvan Majumdar
Ranch Hand

Joined: Feb 22, 2005
Posts: 261
Instead of writing:

write this =>
Alessandro Ilardo
Ranch Hand

Joined: Dec 23, 2005
Posts: 218
I did.

File fileOnDisk = new File(sysPath,formFile.getFileName());


this is the result:

10:04:06,533 DEBUG [AttachmentImplService] [saveFile] Ready to write on file system.
10:04:06,533 DEBUG [AttachmentImplService] [saveFile] System path is
/home/jboss/temp
test_file.pdf
10:04:06,533 DEBUG [AttachmentImplService] [saveFile] File name is test_file.pdf
10:04:06,533 DEBUG [AttachmentImplService] [saveFile] Path is
/home/jboss/temp
/test_file.pdf
10:04:06,533 DEBUG [AttachmentImplService] [saveFile] Absolute path is /var/lib/jboss-4.0.5.GA/bin/
/home/jboss/temp
/test_file.pdf
10:04:06,533 WARN [AttachmentImplService] [saveFile] No sufficient privilege to read into this path.
10:04:06,533 WARN [AttachmentImplService] [saveFile] No sufficient privilege to read into this path.
10:04:06,533 ERROR [AttachmentImplService] [saveFile] No sufficient privilege to write into this path.
10:04:06,533 ERROR [AttachmentImplService] [saveFile] No sufficient privilege to write into this path.
10:04:06,534 WARN [RequestProcessor] Unhandled Exception thrown: class java.io.IOException
10:04:06,534 WARN [[action]] Servlet.service() for servlet action threw exception
java.io.IOException: [saveFile] No sufficient privilege to write into this path.
at it.federfarma.modena.web.service.press.AttachmentImplService.saveFile(AttachmentImplService.java:136)
at it.federfarma.modena.struts.action.press.PressDispatchAction.processAttachment(PressDispatchAction.java:424)
at it.federfarma.modena.struts.action.press.PressDispatchAction.create(PressDispatchAction.java:207)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.apache.struts.actions.DispatchAction.dispatchMethod(DispatchAction.java:270)
at org.apache.struts.actions.DispatchAction.execute(DispatchAction.java:187)
at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:431)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:236)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1196)
at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:432)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:175)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:524)
at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:74)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
at org.jboss.web.tomcat.tc5.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:156)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:869)
at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:664)
at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
at org.apache.tomcat.util.net.MasterSlaveWorkerThread.run(MasterSlaveWorkerThread.java:112)
at java.lang.Thread.run(Thread.java:595)


Just a question. From the console, the path and file name appear on different lines. Is it normal?

Thanks for your help.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: upload File and save into a directory
 
Similar Threads
ClassCastException on Oracle ArrayDescriptor
Caused by: java.lang.IncompatibleClassChangeError: org/apache/mina/common/support/DefaultExceptionMo
ERROR [LoginAction] LoginUseCase - Unexpected exception when creating the session bean object
Problem Installing
Struts menu not working properly in Jboss