Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile 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
  • 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
  • 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
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic