This week's book giveaway is in the Performance forum.
We're giving away four copies of The Java Performance Companion and have Charlie Hunt, Monica Beckwith, Poonam Parhar, & Bengt Rutisson on-line!
See this thread for details.
Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Servlets example

 
Arathi Raj
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.util.*;
public class test extends HttpServlet{
public void doGet(HttpServletRequest req,
HttpServletResponse res)
throws ServletException, IOException{

res.setContentType("application/msword");

//Get an output stream
PrintWriter out = res.getWriter();

//Construct an HTML page to return to the client
out.println("<HTML>");
out.println("<HEAD><TITLE=Test</TITLE></HEAD>");
out.println("<BODY>");
out.println("<h1 align=\"center\">"
+"<font color=\"#FF0000\">");
out.println("Hello World");
out.println("</font></h1>");
out.println("</BODY></HTML>");
out.println("hello");
}//end doGet()
}//end class Servlet01
When I tried to run this code. It opens in msword format, but without any result in that like Hello world. Why is it so. Can anyone explain where I might have gone wrong.
Thanks
Arathi
 
Pradeep bhatt
Ranch Hand
Posts: 8927
Firefox Browser Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just try to add out.close() method
 
leo blk
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
try added the doPost

public void doPost(HttpServletRequest request, HttpServletResponse respone) throws ServletException,IOException
{
doGet(req, res);
}
 
leo blk
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
here is the correct code

public void doPost(HttpServletRequest request, HttpServletResponse respone) throws ServletException,IOException
{
doGet(request, response);
}
 
Dana Hanna
Ranch Hand
Posts: 227
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why are you sending a content type of MSWord, but then writing HTML???
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic