• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Servlet

 
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,
I have recently started learning Servlets.Till now I wrote the code on Notepad and executed the servlet on Sun Server. Today, I wrote the code on NetBeans. The servlet is running successfully but is not giving the correct output.
I created an application by name Servlet1.Under it, i created the servlet, FirstServlet in pack1 package by right clicking the Web Pages folder.
my code was as follows:

public class FirstServlet extends HttpServlet
{

protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
{
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
try {
out.println("Om Namah Shivaya");
} finally {
out.close();
}
}

I did not edit the HTML document in index.jsp.
The output therefore was Hello World!
So what is the use of println() method. why is not my object being called.
I thought the web.xml automatically modifies the HTML document based on the servlet code.

Thanks in advance,

Regards
Komal
[ October 13, 2008: Message edited by: Komal Amaresh ]
 
author
Posts: 5856
7
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What are the contents of your web.xml file, and what URL were you using? Most app servers will serve a file named index.jsp (or index.some-extension) by default.
 
reply
    Bookmark Topic Watch Topic
  • New Topic