Hi Yoav, 
Thanks for the response. I do not get the 404 error anymore after
implementing the changes. But when I access the servlet using 
http://host:port/myApp/HelloServlet,
I  do not get get any response and I get a blank screen.  I am
attaching my modified  servlet code and web.xml

Why am I getting the blank sceen (no response???). Thank you for the
help. Any suggestions?


Servlet code
-----------------

import javax.servlet.http.*;
import java.io.*;
import javax.servlet.ServletException;
import javax.servlet.ServletConfig;
import javax.servlet.ServletContext;

public class HelloServlet extends HttpServlet
{  private ServletConfig config;

        public void init(ServletConfig config) throws ServletException
        {this.config=config;
        System.out.println("***Init");
        }


        public void doGet(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException
        {
                System.out.println("***Service method");
                ServletContext context=getServletConfig().getServletContext();
                String name=context.getInitParameter("name");

                String favoriteOS= config.getInitParameter("favoriteOS");

                res.setContentType("text/html");
                PrintWriter out=res.getWriter();
                out.println("<html><body>Hello World");
                out.println("context parameter name: "+ name);
                out.println("config parameter favoriteOS:"+ favoriteOS);
                out.println("</body></html>");
                out.close();
        }

}

web.xml
--------------

<servlet>
    <servlet-name>HelloServlet</servlet-name>
    <servlet-class>test.HelloServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
  </servlet>
  

  <servlet-mapping>
    <servlet-name>HelloServlet</servlet-name>
    <url-pattern>/HelloServlet</url-pattern>
  </servlet-mapping>


  <welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
  </welcome-file-list>
  

------------------



















On Thu, 26 Aug 2004 15:12:59 -0400, Shapira, Yoav <[EMAIL PROTECTED]> wrote:
> 
> Hi,
> Is your application named HelloServlet also?  If so, I suggest changing
> its name to reduce confusion.  Call it "myApp" or whatever you want.
> 
> Next, correct the actual code of your servlet.  Having an empty
> service() method means your servlet will do nothing.  Take out that
> method completely so that the parent class' service method is used.
> 
> I also suggest putting your servlet in a package, e.g.
> com.mycompany.HelloServlet.  Modify web.xml accordingly, specifically
> the <servlet-class> element.
> 
> Take out the trailing slash from the url-pattern element of the
> servlet-mapping.  Take out the leading slash from the /index.jsp
> welcome-file.  These two changes are not strictly needed but are better
> style.
> 
> Then restart tomcat.  You should be able to access your servlet at
> http://yourhost:yourport/myApp/HelloServlet.
> 
> And if you haven't done so already, make sure to read
> http://jakarta.apache.org/tomcat/tomcat-5.0-doc/appdev/index.html.
> 
> Yoav Shapira
> Millennium Research Informatics
> 
> 
> 
> 
> >-----Original Message-----
> >From: Preeti Iyer [mailto:[EMAIL PROTECTED]
> >Sent: Thursday, August 26, 2004 3:06 PM
> >To: [EMAIL PROTECTED]
> >Subject: 404 error accessing servlet in Tomcat5
> >
> >Hi,
> >I have a simple webapp with 1servler. When I run my webapp in Tomcat5
> >and try accessing my servlet using
> >http://localhost:8080/HelloServlet/HelloServlet , I get a 404 error
> >page stating --
> >
> >HTTP Status 404 - /HelloServlet/HelloServlet
> >type Status report
> >message /HelloServlet/HelloServlet
> >
> >description The requested resource (/HelloServlet/HelloServlet) is not
> >available.
> >Apache Tomcat/5.0.19
> >-----
> >
> >The following is the servlet code:---
> >
> >import javax.servlet.http.*;
> >import java.io.*;
> >import javax.servlet.ServletException;
> >import javax.servlet.ServletConfig;
> >import javax.servlet.ServletContext;
> >
> >public class HelloServlet extends HttpServlet
> >{  private ServletConfig config;
> >
> >       public void init(ServletConfig config) throws ServletException
> >       {this.config=config;}
> >
> >       public void service(HttpServletRequest req, HttpServletResponse
> res)
> >throws ServletException,IOException
> >
> >       {}
> >
> >       public void doGet(HttpServletRequest req, HttpServletResponse
> res)
> >throws ServletException, IOException
> >       {doPost(req,res);}
> >
> >       public void doPost(HttpServletRequest req, HttpServletResponse
> res)
> >throws ServletException, IOException
> >       {
> >               ServletContext context=getServletContext();
> >               String name=context.getInitParameter("name");
> >
> >               res.setContentType("text/html");
> >               PrintWriter out=res.getWriter();
> >               out.println("<html><body>Hello World");
> >               out.println("context parameter name: "+ name);
> >               out.println("</body></html>");
> >               out.close();
> >       }
> >
> >}
> >
> >------------
> >
> >The following is the web.xml---------
> >
> ><?xml version="1.0" encoding="UTF-8"?>
> ><!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web
> >Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd";>
> >
> ><web-app>
> >
> ><context-param>
> ><param-name>name</param-name>
> ><param-value>pi</param-value>
> ></context-param>
> >
> > <servlet>
> >   <servlet-name>HelloServlet</servlet-name>
> >   <servlet-class>HelloServlet</servlet-class>
> >   <load-on-startup>1</load-on-startup>
> > </servlet>
> >
> > <servlet-mapping>
> >   <servlet-name>HelloServlet</servlet-name>
> >   <url-pattern>/HelloServlet/</url-pattern>
> > </servlet-mapping>
> >
> > <session-config>
> >   <session-timeout>270</session-timeout>
> > </session-config>
> >
> > <welcome-file-list>
> >   <welcome-file>/index.jsp</welcome-file>
> > </welcome-file-list>
> >
> ></web-app>
> >--------
> >
> >I am able to access index.jsp by using
> http://localhost:8080/HelloServlet/
> >What do I need to do to be able to access the servlet class? Do I need
> >to do some special kind of configuration in Tomcat?
> >
> >Thanks in advance for the help.
> >
> >---------------------------------------------------------------------
> >To unsubscribe, e-mail: [EMAIL PROTECTED]
> >For additional commands, e-mail: [EMAIL PROTECTED]
> 
> This e-mail, including any attachments, is a confidential business communication, 
> and may contain information that is confidential, proprietary and/or privileged.  
> This e-mail is intended only for the individual(s) to whom it is addressed, and may 
> not be saved, copied, printed, disclosed or used by anyone else.  If you are not 
> the(an) intended recipient, please immediately delete this e-mail from your computer 
> system and notify the sender.  Thank you.
> 
>

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to