File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

New to servlet - need help with print writer

 
Rahul Sudip Bose
Ranch Hand
Posts: 637
Eclipse IDE Firefox Browser Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
import java.io.*;
import javax.servlet.*;

public class SecondClass extends GenericServlet
{

public void service(ServletRequest request,ServletResponse response)throws ServletException,IOException
{
response.setContentType("text/html");
PrintWriter out=response.getWriter(); // LINE 1
out.println("welcome to servlet ! ");
out.close();
}

}

Can someone tell me how does PrintWriter work ? Please explain LINE 1 also.
 
Ninad Kulkarni
Ranch Hand
Posts: 802
Hibernate Linux Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
UseCodeTags
It is very easy to read code.

rahul boseofindia wrote:Can someone tell me how does PrintWriter work ?

I think this question is not related to servlet
You can see this

rahul boseofindia wrote:Please explain LINE 1 also.

This will return PrintWriter object
See Servlet API





 
Malatesh Karabisti
Ranch Hand
Posts: 153
Java Oracle
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rahul,

PrintWriter is the class which helps to print output in the specified locations like FileOutputStrem/File/Console. in the above code what you need to understand is from the response object we can obtain the writer which helps out send the required out put to client.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic