This week's book giveaway is in the Java in General forum.
We're giving away four copies of Think Java: How to Think Like a Computer Scientist and have Allen B. Downey & Chris Mayfield on-line!
See this thread for details.
Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

HttpServletResponse& HttpServletRequest

 
S Varana
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
<pre>
public class SimpleServlet extends HttpServlet
{
/**
* Handle the HTTP GET method by building a simple web page.
*/
public void doGet (HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException
{
PrintWriterout;
Stringtitle = "Simple Servlet Output";
// set content type and other response header fields first
response.setContentType("text/html");
// then write the data of the response
out = response.getWriter();
out.println("<HTML><HEAD><TITLE>");
out.println(title);
out.println("</TITLE></HEAD><BODY>");
out.println("<H1>" + title + "</H1>");
out.println("<P>This is output from SimpleServlet.");
out.println("</BODY></HTML>");
out.close();
}
}
</pre>
HttpServletResponse & HttpServletRequest
In the Java API they are defined as interfaces
but i do not find the method "setContentType"
From where is the method "setContentType"
coming
Please explain me.
 
Ashish Thakur
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The HttpServletResponse & Request are extended from the ServletRequest and Response in the javax.servlet package.
It is from here that the setContentType is taken.
Good Luck ,
Bye
Ashish T.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic