1
在Struts操作类中,如何获取应用程序路径?Weblogic服务器中的应用程序路径
我想从web内容 \的applicationName \ CONFIG \ myxml.xml
由于读取XML文件。
在Struts操作类中,如何获取应用程序路径?Weblogic服务器中的应用程序路径
我想从web内容 \的applicationName \ CONFIG \ myxml.xml
由于读取XML文件。
我建议不要将文件保留在该位置,因为这样可以很容易地使用http://yourURl/applicationContext/Config/myxml.xml
公开访问,例如。我想你应该将它移动到WEB-INF
文件夹下。
你应该能够做到像下面(快代码在运行中不抱我吧): -
public ActionForward foo(HttpServletRequest request, HttpServletResponse response){
ServletContext context = request.getSession().getServletConext();
InputStream stream = context.getResourceAsStream("Config/myxml.xml");
if(stream!=null){
//load your XML file from the stream
}
}
如果您正在使用Struts2的,那么你可以访问使用ServletActionContext作为ServletContext中好: -
ServletContext context = ServletActionContext.getServletContext();