| Author |
New to servlet - need help with print writer
|
Rahul Sudip Bose
Ranch Hand
Joined: Jan 21, 2011
Posts: 637
|
|
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.
|
SCJP 6. Learning more now.
|
 |
Ninad Kulkarni
Ranch Hand
Joined: Aug 31, 2007
Posts: 774
|
|
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
|
SCJP 5.0 - JavaRanch FAQ - Java Beginners FAQ - SCJP FAQ - SCJP Mock Tests - Tutorial - JavaSE7 - JavaEE6 -Generics FAQ - JLS - JVM Spec - Java FAQs - Smart Questions
|
 |
Malatesh Karabisti
Ranch Hand
Joined: Jul 28, 2010
Posts: 143
|
|
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.
|
 |
 |
|
|
subject: New to servlet - need help with print writer
|
|
|