Pages

Thursday, February 21, 2013

Printing output to the browser using Servlets


In general the output is printed to the Apache Command Line but if we want to print the output to the Web Browser we will use the PrintWriter class declared in the java.io.* package.

Providing output to the browser is the step to be used in response and hence we use the response variable provided in the service(ServletRequest req, ServletResponse res)method as
PrintWriter pw = res.getWriter();pw.println(“Hello”);
Example Program:  http://pastie.org/6282996
Servlet Project for PrintWriter : https://www.box.com/s/i57j4qcteemz7ad3w491
Program Output : 


0 comments:

Post a Comment