Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

printing an xml file to screen that is not in htdocs folder 1

Status
Not open for further replies.

keak

Programmer
Sep 12, 2005
247
CA
Hi there,

I was wondering if there is a way to create an xml page on the fly with jsp by reading in an xml file on the server (this file is not located in the htdocs folder so a regular a href=file.xml wont work ...)

Currently, I have

Code:
    String directory = "/home/apache/htdocs/myfolder";
    File file = new File(directory);
    File[] content = file.listFiles();
    Arrays.sort(content);
    for (int i=0; i<content.length; i++) {
        out.println("<br><a href='myfolder" + content[i].getName() + "'>" + content[i].getName() + "</a>");
    }

This will only work via browser my xml files were in /htdocs/myfolder.

Is there a way to print xml files that are not in this folder in similar methods?



 
I think I figured the way to returl xml, however, this only seem to work in IE; firefox dowsn't show the formatted xml in the browser? Any ideas why this may be happening?

I noticed that there is a large amount of blank lines at the top of the xml's first line when I view source (I am guessing that the import statements are causing this); perhaps this is why firefox is not registering it as an xml?

If so, is there any way to prevent the import statement to insert blank lines in the http response that its giving out?

Code:
    String directory = "/home/user1/xmlfiles";
    BufferedReader input = new BufferedReader(new FileReader(directory+xmlfile));
    out.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
    //out.write(directory+xmlfile);
    String line = "";
    while ((line = input.readLine()) != null) {
        out.println(line);
 
Hi,

Try setting the contentType to "XML" in the jsp page

Code:
response.setContentType("text/xml");

Cheers
Venu
 
Thanks Venur,
That did just the trick!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top