This should give you the real path that you can use to extract / edit files.
This should give you the real path that you can use to extract / edit files. Javadoc Link We're doing something similar in a context listener. Public class MyServlet extends HttpServlet { public void init(final ServletConfig config) { final String context = config.
GetServletContext(). GetRealPath("/"); ... } ... }.
Brilliant! Exactly what I was after. I suspect this is what wrumsby was shooting for in his answer.
Thanks guys. The quality of content on this site continues to impress me. – Casey Watson Sep 12 '08 at 5:56.
Do you mean: public class MyServlet extends HttpServlet { public void init(final ServletConfig config) { final String context = config. GetServletContext(); ... } ... } Or something more complex?
This might be the right path but I don't think it gets me all of the way there. I still need to be able to open files that are in the context directory. – Casey Watson Sep 11 '08 at 20:42.
I was googling the result and getting no where. In Jsp pages that need to use Java Script to access the current contextPath it is actually quite easy. Just put the following lines into your html head inside a script block.
// set up a global java script variable to access the context path var contextPath = "${request. ContextPath}.
In my Servlet I would like to access the root of the context so that I can do some JavaScript minifying You can also access the files in the WebContent by ServletContext#getResource(). So if your JS file is for example located at WebContent/js/file. Js then you can use the following in your Servlet to get a File handle of it: File file = new File(getServletContext().
GetResource("/js/file. Js").getFile()); or to get an InputStream: InputStream input = getServletContext(). GetResourceAsStream("/js/file.
Js"); That said, how often do you need to minify JS files? I have never seen the need for request-based minifying, it would only unnecessarily add much overhead. You probably want to do it only once during application's startup.
If so, then using a Servlet for this is a bad idea. Better use ServletContextListener and do your thing on contextInitialized().
I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.