File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes Trying to print XML using a servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Trying to print XML using a servlet" Watch "Trying to print XML using a servlet" New topic
Author

Trying to print XML using a servlet

Malika Jaiswal
Greenhorn

Joined: Jul 17, 2006
Posts: 4
Hi ,

I am trying to print an XML file using a servlet but its not working. I am calling the servlet from an html file by giving the name as an input parameter and then submitting it.

I am trying to use it using a BufferedReader

BufferedReader br = new BufferedReader(new FileReader(filename));
String nextLine = "";
StringBuffer sb = new StringBuffer();
while ((nextLine = br.readLine()) != null) {
sb.append(nextLine);

sb.append("\n");
}

I want to display the response on the browser . Are there other APIs for servlets ? Please help, need poinetrs as I am new to this field.
Thanks,
Malika
A Kumar
Ranch Hand

Joined: Jul 04, 2004
Posts: 979
How did you set the response content type??
Malika Jaiswal
Greenhorn

Joined: Jul 17, 2006
Posts: 4
I set it to text/html
response.setContentType("text/html; charset=UTF-8");
A Kumar
Ranch Hand

Joined: Jul 04, 2004
Posts: 979
can you post the code if possible??
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12682
    
    5
BufferedReader br = new BufferedReader(new FileReader(filename));


That looks like your problem right there. With only the file name, the FileReader will look in the "current" directory - something you have no control over in the servlet environment. You MUST provide a complete path.

When you tried this code you should have gotten an informative error message or had one show up in the logs.

Bill


Java Resources at www.wbrogden.com
Malika Jaiswal
Greenhorn

Joined: Jul 17, 2006
Posts: 4
Yeah, I realised that was the problem. Thanks!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Trying to print XML using a servlet
 
Similar Threads
Facing problem in IO stream operation
Bufferedreader error issue
Reading XML file as String is not working properly
Broken Tags in XML Response using DOM
Looping StringBuffer