I am having a string which needs to be sent as response from a servlet & I am having two approaches to send response back from it.
First is using PrintWriter.
<
I am having a string specifies that you wish to write a string so i suggest the PrintWriter object
//prints text data to screen (browser)
PrintWriter printer = response.getWriter();
printer.print(string);
//print again if you wish
printer.print("Welcome blahblah");
//close afterwards if you don't mind.
printer.close();
so if you wish to write text to browser, PrintWriter works just fine, fast and simple.