aspose file tools*
The moose likes Servlets and the fly likes Servlets example Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Servlets example" Watch "Servlets example" New topic
Author

Servlets example

Arathi Raj
Ranch Hand

Joined: Nov 22, 2002
Posts: 90
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

Joined: Feb 27, 2002
Posts: 8919

Just try to add out.close() method


Groovy
leo blk
Greenhorn

Joined: Feb 03, 2003
Posts: 6
try added the doPost

public void doPost(HttpServletRequest request, HttpServletResponse respone) throws ServletException,IOException
{
doGet(req, res);
}
leo blk
Greenhorn

Joined: Feb 03, 2003
Posts: 6
here is the correct code

public void doPost(HttpServletRequest request, HttpServletResponse respone) throws ServletException,IOException
{
doGet(request, response);
}
Dana Hanna
Ranch Hand

Joined: Feb 28, 2003
Posts: 227
Why are you sending a content type of MSWord, but then writing HTML???
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Servlets example