java - What is the proper way to tell a servlet the location of a file? -


i hardcode location in web.xml, makes need change web.xml everytime during deployment.

can make folder inside project , tell servlet folder , file underneath it?

<context-param>         <param-name>iptable</param-name>         <param-value>e:\workspace\eclipse_workspace\bpspdfbill\webcontent\web-inf\iptable.txt</param-value> </context-param> 

if don't need file object, can use servletcontext.getresource(string path). path argument must begin '/', , relative context root. method returns url, can open , read contents of file.

i don't think there standard method of getting pointer file object. use system property, that's no better putting in web.xml.

update

if really need file object, , not contents of file, there couple of things can do. depends on how location of file changes.

if file location changes based on server deploying to, stays same on each server, add system property web container's startup scripts. how this, of course, varies container, should able find out how in documentation.

you put location of file in separate properties file, file.properties, , modify deployment process generate or update file , place in web-inf directory. can read properties file servletcontext.getresourceasstream(), path, , instantiate file.


Comments

Popular posts from this blog

c++ - Is it possible to compile a VST on linux? -

java - Output of Eclipse is rubbish -

jquery - Confused with JSON data and normal data in Django ajax request -