Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4616788
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T02:01:58+00:00 2026-05-22T02:01:58+00:00

I’m working through the Java Ranch Cattle Drive online tutorials and got up to

  • 0

I’m working through the Java Ranch Cattle Drive online tutorials and got up to the Servlets projects. I wanted to install and run Apache instead of Orion, because I wanted to learn a more mainstream HTTP server.

I got Apache up and running on my machine (this is a Windows XP/Cygwin environment, so I’m using the Apache package that comes with the latest version of cygwin, currently httpd version 1.3.33)

I’m to the point of directing a browser to http://localhost and the server is correctly fetching the welcome page (index.html) at C:\cygwin\var\www\htdocs.

I’ve installed Java EE and was able to compile the following Servlet:

import java.io.* ;
import javax.servlet.http.* ;

public class BeeServlet extends HttpServlet
{

    public void doGet( HttpServletRequest request , HttpServletResponse response )
    {
        response.setContentType("text/html");
        try
        {
            PrintWriter out = response.getWriter();
            out.println( "a-buzz-buzz ..." );
            out.close();
        }
        catch( Exception e )
        {
            System.out.println( "cannot get writer: " + e );
        }
    }

}

This compiles into a .class file without errors. My question is, where do I install this file in the server?

The file is called BeeServlet.class and the tutorial says to direct a browser to http://localhost/servlet/BeeServlet after installing the BeeServlet.class in the appropriate directory in the web server.

(EDIT: I’ve successfully installed Tomcat and have the basic welcome page showing, as explained in the steps below. I’m still not sure where to put the .class file though or how to access it):

Here’s are the steps of installing Tomcat and running it through Cygwin:

  1. Go to http://tomcat.apache.org/ and download the latest version of Tomcat (for the above system configuration, select the 32-bit/64-bit Windows Service Installer method, which will create a 9 MB installation at C:\Program Files\Apache Software Foundation\Tomcat 7.0).

  2. Add this path to the Windows system environment variable ‘Path’

  3. Start a Cygwin bash shell

  4. type ‘tomcat7’ (with Path set, it will find this .exe in the above path). This will start the tomcat server.

  5. Start a browser and direct it to http://localhost:8080. This will bring up the Tomcat welcome screen (which is really Tomcat reading the file: C:\Program Files\Apache Software Foundation\Tomcat 7.0\webapps\ROOT\index.jsp).

  6. Create new directories under C:\Program Files\Apache Software Foundation\Tomcat 7.0\webapps named examples\WEB-INF\classes.

  7. Add a @WebServlet annotation to the source code file (this would be located after any imports): @WebServlet(urlPatterns={“/servlet/BeeServlet”}). Compile the BeeServlet.java file and place the .class file in C:\Program Files\Apache Software Foundation\Tomcat 7.0\webapps\examples\WEB-INF\classes\BeeServlet.class

  8. Direct your browser to http://localhost:8080/examples/servlet/BeeServlet

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T02:01:59+00:00Added an answer on May 22, 2026 at 2:01 am

    You need to let the servletcontainer know that you’ve a servlet which it has to execute. Since you’re already on Tomcat 7.0, a @WebServlet annotation should suffice.

    @WebServlet(urlPatterns={"/servlet/BeeServlet"})
    public class BeeServlet extends HttpServlet {
        // ...
    }
    

    Or the old way (probably as the JavaRanch tutorial should have mentioned), by a declaration in web.xml.

    <servlet>
        <servlet-name>beeServlet</servlet-name>
        <servlet-class>BeeServlet</servlet-class>
    </servlet>
    <servlet-mapping>
        <servlet-name>beeServlet</servlet-name>
        <url-pattern>/servlet/BeeServlet</url-pattern>
    </servlet-mapping>
    

    Please note that putting classes in a default package is a bad practice. You should be placing classes in a package if you want them to be visible to classes inside a package. The servletcontainer, written in pure Java, needs to be able to see them as well. Now, Tomcat has hacks for this, but this works in specific versions/configurations only. Always, always put servlet classes in a package.

    See also:

    • Our servlets wiki page

    Unrelated to the concrete problem:

    I’ve installed Java EE

    Please note that the Java EE download from Oracle.com contains basically the Glassfish application server along with some documentation. You don’t need it when all you want is just running servlets on Tomcat.

    See also:

    • Java SE or Java EE (standard or enterprise)?
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.