image uploading - Configure a constant in Tomcat -
image uploading - Configure a constant in Tomcat -
i want provide upload functionality in website. cannot save uploaded image within war. can save particular location on machine , refer there. problem have create code compatible windows machine, mac , openshift server. path images folder different on different machines.
the workaround thinking somehow configure images folder location in tomcat server on different machines , read there. there way configure variable within tomcat? there improve solution problem?
option 1
you can define environment variable in context configuration file.
<context> <environment name="myapp.upload.dir" type="java.lang.string" value="/srv/app/upload" override="true" /> </context>
you can either create new context file application or set environment entry in $tomcat_home/conf/context.xml
in case property accessible applications running in tomcat instance. here tomcat documentation contexts.
to access variable value utilize next code:
initialcontext ctx = new initialcontext(); string uploaddir = (string) ctx.lookup("java:comp/env/myapp.upload.dir");
option 2
you specify jvm property in $tomcat_home/bin/setenv.sh
(or $tomcat_home\bin\setenv.bat
on windows) , retrieve so:
system.getproperty("myapp.upload.dir");
personally think first solution cleaner.
also final note, not think of solution workaround. acceptable solution specify things upload directory in sort of configuration file rather have 1 fixed location works platform can't changed (for illustration $home/app/upload
).
tomcat image-uploading
Comments
Post a Comment