• 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

null pointer exception while creating file from resources in managed bean classs

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i want to list files from resources folder like this:



but it give me a null pointer exception on fList
the directory of resources is :



How is this caused and how can I solve it?
 
Ranch Hand
Posts: 133
Hibernate Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
which line in the code, are you getting this exception at?
 
Saloon Keeper
Posts: 27763
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
One problem with this approach is that the official storage format for a J2EE webapp is a WAR File. Your resources, when in a WAR wouldn't be accessible as filesystem objects, thus any attempt to access them using java.io.File would fail. You could do so if the WAR had been "exploded" (unzipped), but exploded form is not part of the J2Ee standard, so doing so would violation the J2EE standard. Also, since webapp servers have no concept of "current directory", whether within a WAR or not, a relative pathname would be extremely risky to use, assuming it ever functioned at all.

The safer way to get at WAR resources is to use the HttpServletRequest getResource methods, which take as their pathnames an "absolute" resource location. Absolute relative to the root of the WAR, that is. So a resource path of "/WEB-inf/classes/log4j.xml" would return access to the log4j.xml "file" (see above) in a J2EE-compliant way. Note that the leading slash is mandatory, since it's an absolute path.

I'm not sure that theres a method that will enumerate WAR resources or not without reading the docs. Since a WAR is supposed to be read-only, you could always create a resource that contains the list of resources in it. If, on the other hand, the list of resources is subject to change, you might find it better to place them in a real directory somewhere outside both the WAR and the webapp server.
 
mostafa jamareh
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

rohit chavan wrote:which line in the code, are you getting this exception at?


thanks rohit , on line 10
 
rubbery bacon. crispy tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic