Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Java > Java Open Source > Apache Tomcat
|
Apache Tomcat General discussion of the Apache Tomcat servlet container. For discussions specific to the Professional Apache Tomcat book, please see the book discussion forum for that book.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Apache Tomcat section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 10th, 2004, 08:03 PM
Registered User
 
Join Date: Dec 2004
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Tomcat and servlet error - beginner's question

* I created a "myApp" directory inside of the "webapps" directory.

* Added the "web.xml" file at the webapps/myApp/WEF-INF level.

* Then, I created a simple HelloServlet.java file and added the classfile in the webapps/myApp/WEB-INF/classes directory.

* The web.xml has the following form:

    <?xml version="1.0" encoding="ISO-8859-1"?>

    <!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>

        <servlet>
            <servlet-name>hello</servlet-name>
            <servlet-class>HelloServlet</servlet-class>
        </servlet>

            <servlet-mapping>
              <servlet-name>invoker</servlet-name>
              <url-pattern>/servlet/*</url-pattern>
          </servlet-mapping>

    </web-app>

 * After starting Tomcat, when I type the following link in IE, I get an HTTP Status 404 error: "The requested resource (/myApp/hello) is not available."

http://localhost:8080/myApp/hello

Even, the following URL doesn't work -

http://localhost:8080/myApp/servlet/hello


* I put an html file inside the "myApp" directory, and that does get loaded by the browser, so the Tomcat configuration/installation seems to be okay.

* I even tried adding a "Context" element in Tomcat's conf/server.xml file to explicitly define the "myApp" directory, but no use.

Really frustrated why things don't work. Any help would be most appreciated.

Thanks in advance !
 
Old December 10th, 2004, 08:08 PM
Friend of Wrox
 
Join Date: Jul 2004
Posts: 204
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Have you done everything explained in this thread:

http://p2p.wrox.com/topic.asp?TOPIC_ID=19115

 
Old December 10th, 2004, 08:12 PM
Friend of Wrox
 
Join Date: Jul 2004
Posts: 204
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Sorry, should mention there's some dodgey stuff in that thread which you do not need to do. Start with the stuff on uncommenting elements within Tomcat5\conf\web.xml


 
Old December 15th, 2004, 10:25 PM
Registered User
 
Join Date: Dec 2004
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I did as mentioned in the thread, but no use. To make matters simple, I decided to move my servlet class to the ROOT directory.

I now have the following directory structure:

<Tomcat_install_dir>/webapps/ROOT/WEB-INF/classes/sample/HelloServlet.class

The package name for the servlet class is "sample".

I started Tomcat and typed the following URL in IE:

http://localhost:8080/servlet/sample/HelloServlet

but got the 404 HTTP status error msg: "The requested resource (/servlet/sample/HelloServlet) is not available."

Is there anything else I need to do ????? The Tomcat example servlet does get loaded and the browser displays the text, but not for my servlet :-(

If it might help, here is the text for the HelloServlet class:
------------------

package sample;

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

public class HelloServlet extends HttpServlet
{
    public void doGet(HttpServletRequest request, HttpServletResponse response)
                throws ServletException, IOException
    {
        response.setContentType("text/html");
        PrintWriter out = response.getWriter();
        out.println("<HTML>");
        out.println("<HEAD>");
        out.println("<TITLE>Hello</TITLE>");
        out.println("</HEAD>");
        out.println("<BODY>");
        out.println("Hello!");
        out.println("</BODY>");
        out.println("<?HTML>");
    }
}

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

 
Old December 16th, 2004, 08:42 AM
Friend of Wrox
 
Join Date: Jul 2004
Posts: 204
Thanks: 0
Thanked 0 Times in 0 Posts
Default

You MUST have 'servlet' in the URL, try

http://localhost:8080/servlet/myApp/hello

Have you uncommented the lines explained earlier in the thread?


 
Old January 15th, 2005, 09:37 PM
Registered User
 
Join Date: Jan 2005
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

yep, try including 'servlet" in the URL... That should do it... You code looks right...






Similar Threads
Thread Thread Starter Forum Replies Last Post
A beginner's question Gene Reginato XSLT 5 May 17th, 2007 10:32 AM
Beginner's Question peytontodd Beginning VB 6 3 March 7th, 2007 11:58 AM
Help please: another beginner's question savoym C# 1 January 9th, 2004 11:45 AM
Beginner's question savoym C# 2 January 8th, 2004 03:58 PM
Beginner's SQL question pankaj_daga SQL Language 3 November 12th, 2003 07:57 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.