开发者

Parse xml which is in private folder(WEB-INf)

I want to parse xml. I used jQuery ajax for it. But th开发者_高级运维e problem with it as someone suggest me in my other post is my xml is in WEB-INF which is by default private. So I can not parse it through ajax. Then please suggest me some other way to parse my xml which is in WEB-INf. I need to parse it in javascript tag.


You can make a servlet that accesses to that XML and prints out its content. Then, you can invoke that servlet from your javascript file and process it.

If you have to reach that xml file, perhaps the WEB-INF folder is not the best place for that file.


This is a dirty solution, but it works

<%@ page contentType="text/xml"%>
<%
    java.io.File f = new java.io.File(getServletContext().getRealPath("/WEB-INF/web.xml")); //your XML file HERE
    char[] c = new char[(int)f.length()];
    java.io.FileReader fr = new java.io.FileReader(f);
    int i = 0;
    int count = 0;
    while((i = fr.read()) != -1){
        c[count++] = (char)i;
    }

    out.print(c);
%>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜