采用request.getServletContext().getRealPath(“”) 获取当前jsp绝对路径
采用request.getServletPath() 获取相对路径
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
Document document = db.parse(request.getServletContext().getRealPath("")+request.getServletPath().substring(1, request.getServletPath().length()).replace("index.jsp","")+"xmls/buttom_context.xml");
NodeList nl = document.getElementsByTagName("addr");
这是一段java代码,这个代可以读取当前jsp路径下的相对内容
request.getServletContext().getRealPath("")+request.getServletPath().substring(1, request.getServletPath().length()).replace("index.jsp","")
是用于获取当前jsp的路径,那么其他的文件可以在这里进行读取