• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

upload File and save into a directory

 
Ranch Hand
Posts: 218
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Ranch Hand
Posts: 261
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 218
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 261
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Instead of writing:

write this =>
 
Alessandro Ilardo
Ranch Hand
Posts: 218
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic