Win a copy of Svelte and Sapper in Action this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Servlets example

 
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
 
Ranch Hand
Posts: 8943
Firefox Browser Spring Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just try to add out.close() method
 
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);
}
 
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???
 
She's brilliant. She can see what can be and is not limited to what is. And she knows this tiny ad:
the value of filler advertising in 2020
https://coderanch.com/t/730886/filler-advertising
    Bookmark Topic Watch Topic
  • New Topic