Saturday, June 9, 2007

Get file path under WEB-INF directory in struts2

In struts2, we can use this method to get file path in WEB-INF directory

ServletContext servletContext = ServletActionContext.getServletContext();
String file = servletContext.getRealPath("/WEB-INF/xxx.xml");

here, we can get the file absolute path.
If we use servletContext.getResource("/WEB-INF/xxx.xml") method, we will get the jndi url fot the given file. For example, jndi:/localhost/WEB-INF/xxx.xml.

No comments: