java - Servlet context get real path returns null -


i ma trying access resource src/main/webapp/

i using java 1.8.0_101 , maven 3.0.3

unfortunately, working in 1 environment , not in unix environment

@named @applicationscoped public class testclass {      private static final string resource = "/resources/css/test.css";     private string css = "";      public void init(@observes @initialized(applicationscoped.class) servletcontext servletcontext) throws ioexception {         string pathstring = servletcontext.getrealpath(resource);         system.out.println("path string: " + pathstring);         byte[] data = files.readallbytes(paths.get(pathstring));         css = new string(data, "utf-8");     }      public string getcss() {         return css;     }      public string format(object o) {         if (o instanceof list) {             list<?> list = (list<?>) o;             string text = list.tostring();             return text.substring(1, text.length() - 1);         }         return o == null ? "" : o.tostring();     }  } 

please check this

servletcontext servletcontext = request.getsession().getservletcontext(); string relativewebpath = "img/image.png"; string absolutediskpath = servletcontext.getrealpath(relativewebpath); 

Comments

Popular posts from this blog

unity3d - Rotate an object to face an opposite direction -

angular - Is it possible to get native element for formControl? -

javascript - Why jQuery Select box change event is now working? -