• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Trying to print XML using a servlet

 
Malika Jaiswal
Greenhorn
Posts: 4
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 980
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How did you set the response content type??
 
Malika Jaiswal
Greenhorn
Posts: 4
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I set it to text/html
response.setContentType("text/html; charset=UTF-8");
 
A Kumar
Ranch Hand
Posts: 980
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
can you post the code if possible??
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13045
6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Malika Jaiswal
Greenhorn
Posts: 4
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yeah, I realised that was the problem. Thanks!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic