2011-08-13 5 views

답변

0

예를 들어 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(); 
관련 문제