Application path in Weblogic server
In Struts action class how do I get the application path?
I want to read an XML file from webcontent开发者_高级运维\applicationName\Config\myxml.xml
Thanks.
I would advise against keeping the file in that location because then it can be easily accessed publicly using http://yourURl/applicationContext/Config/myxml.xml
for example. I think you should move it under the WEB-INF
folder.
You should be able to do something like below (quick code on the fly don't hold me to it):-
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
}
}
If you are using struts2 then you can access the ServletContext using ServletActionContext as well:-
ServletContext context = ServletActionContext.getServletContext();
精彩评论