• 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
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Liutauras Vilda
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Mikalai Zaikin
  • Himai Minh

web.xml and file uploading

 
Ranch Hand
Posts: 285
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a entry in my web.xml as follows:
<servlet>
<servlet-name>
DemoParserUploadServlet
</servlet-name>
<servlet-class>
gsptech.portal.servlets.DemoParserUploadServlet
</servlet-class>
<init-param>
<param-name>uploadDir</param-name><param-value>/temp/portal2/</param-value>
</init-param>
</servlet>

the uploadDir I am accessing in one of my servlets. Now if the temp/portal2 dir is already created it works fine. But I want to make my code where if it no created then it goes and creats it. I cant seem to create the directory. Here is the code in my servlet.
private File dir;
public void init(ServletConfig config) throws ServletException {
super.init(config);

// Read the uploadDir from the servlet parameters
String dirName = config.getInitParameter("uploadDir");

if (dirName == null) {
throw new ServletException("Please supply uploadDir parameter");
}
dir = new File(dirName);
dir.mkdir();
System.out.println("dir.mkdir();" + dir.isDirectory() + " dir:" + dir);
if (! dir.isDirectory()) {

throw new ServletException("Supplied uploadDir " + dirName +
" is invalid");
}
}
***************************
Is till says dir.isDirectory() is false after dir.mkdir().
What am I doing wrong?
 
Ranch Hand
Posts: 3695
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you don't have the proper permissions on the parent directory, then you can't create the sub-directory. If your servlet container belongs to 'www' or some other group, make sure that group has full rwx permissions along the path that you are specifying.

This kind of error (on a Windows system) is quiet. ie: it doesn't throw access or security errors. It simply returns 'false'.
[ April 29, 2002: Message edited by: Mike Curwen ]
 
My, my, aren't you a big fella. Here, have a tiny ad:
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic