Hey, everyone! I truly hope you can help.

I am well aware there have been many, many related questions asked already about this, as well as even more answers. Unfortunately, having tried all this advice I still cannot resolve this problem.

I am trying to launch a simple Java servlet in the browser, following instructions from the textbook:

Java Programming: Comprehensive Concepts and Techniques, Shelly Cashman Series, ISBN: 9781418859855.

I am aware of the advice given here to other people with this/similar problems, that servlets should preferably be written under a package, and not packageless, but I am following the textbook's guidance with this, and of course being a textbook, its method must work. I seek help with doing it in THIS method.

I have a Java servlet, called HTMLBank.java which I successfully compiled with no compilation errors. Now, according to the textbook:

1) Place the .class file into C:\Program Files\Apache Software Foundation\Tomcat 5.5\webapps\ROOT\WEB-INF\classes folder. Yes, the textbook uses the default package for this and the ROOT directory of Tomcat.

2) Run the Tomcat service - it is running (shown as a green "play" arrow in right-bottom of the screen).

3) In the browser, type URL: http://localhost:8080/servlet/HTMLBank and enter it. After doing this, the following error results:

HTTP Status 404 - /servlet/HTMLBank
type Status report
message /servlet/HTMLBank
description The requested resource (/servlet/HTMLBank) is not available.


Now, I might mention that I did succeed in launching a servlet once before, but that was only if I used a package, say com.example and mapped it in the web.xml file, but as stated before, this deviates from the textbook and I need to get it to work using the default package and ROOT directory.

Here is the code of the HTMLBank.java servlet file:

Code:
import javax.servlet.*;
import javax.servlet.http.*;

import java.io.; import java.util.;

public class HTMLBank extends HttpServlet { public void init() throws ServletException {

}

public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
    response.setContentType("text/html");
    PrintWriter out = response.getWriter();

    response.setHeader("Expires", "Tues, 01 Jan 1980 00:00:00 GMT");

    out.println("<html>");
        out.println("<title>Online Bank ATM Simulator</title>");
        out.println("<h1>Tester Text.</h1>");
        out.println("<body>This serves to test functioning of the servlet in browser.</body>");
    out.println("</html>");
}

public void destroy()
{

}
}
Here is the code of the web.xml file:

Code:
<?xml version="1.0" encoding="ISO-8859-1"?>
  http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. -->
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" version="2.4">

Welcome to Tomcat Welcome to Tomcat

<servlet>
    <servlet-name>org.apache.jsp.index_jsp</servlet-name>
    <servlet-class>org.apache.jsp.index_jsp</servlet-class>
</servlet>

<servlet-mapping>
    <servlet-name>org.apache.jsp.index_jsp</servlet-name>
    <url-pattern>/index.jsp</url-pattern>
</servlet-mapping>
<-- added the following for invoker servlet --> invoker org.apache.catalina.servlets.InvokerServlet

<servlet-mapping>
    <servlet-name>invoker</servlet-name>
    <url-pattern>/servlet/*</url-pattern>
</servlet-mapping>
The web.xml file was modified per book guide to allow locating anonymous servlets in the default directory.

Here is the context.xml file:

Code:
<!-- The contents of this file will be loaded for each web application -->
<!-- Default set of monitored resources -->
<WatchedResource>WEB-INF/web.xml</WatchedResource>
<WatchedResource>META-INF/context.xml</WatchedResource>

<!-- Uncomment this to disable session persistence across Tomcat restarts -->
<!--
<Manager pathname="" />
-->
This file was edited to enable servlet reloading, also as per book guide.

The following are paths to all the files/folders involved in this discussion:

C:\Program Files\Apache Software Foundation\Tomcat 5.5\webapps\ROOT\WEB-INF\classes --> I created the "classes" folder, per book guide.

C:\Program Files\Apache Software Foundation\Tomcat 5.5\webapps\ROOT\WEB-INF\classes\HTMLBank.class --> I placed the .class file into here.

C:\Program Files\Apache Software Foundation\Tomcat 5.5\webapps\ROOT\WEB-INF\web.xml --> This is the location of web.xml file which was edited.

C:\Program Files\Apache Software Foundation\Tomcat 5.5\conf\context.xml is the location of the context.xml file which was edited.

So, as I said, I NEED to work the servlet without a package and from ROOT.

Please can somebody help? I greatly appreciate it!