How to run a Tomcat example

Discussion in 'Java' started by Richard, May 30, 2007.

  1. Richard

    Richard Guest

    Hi All,

    Tomcat servlets-examples directory includes an HellowWorld.html
    example. How I am I supposed to run this to as a Tomcat example?

    I've got Tomcat running, as evidenced by the "Apache Tomcat/5.5.12"
    webpage displayed in my Firefox browser at address http://localhost:8080/

    Double-clicking HellowWorld.html
    displays a webpage with the heading "Source Code for HelloWorld
    Example" followed, of course, by HellowWorld.html's text beautifully
    color coded.

    My configuration:
    WinXP-Pro/SP2, Ruby 1.8.2-15, Rails 1.1.6, Gem 0.9, MySQL 5.0.27-nt,
    SciTE 1.72,
    FireFox 2.0.0.1, IE 7.0, OE 6.0, MS Office 2003 SP2,
    Java JVM 1.5.0_11-b03, Apache Tomcat/5.5.12,
    AVG-Free 7.5.430, Prevx1 2.0.2.23, Startup Cop Pro 2.03

    TIA,
    Richard
     
    Richard, May 30, 2007
    #1
    1. Advertising

  2. Richard

    Carl Guest

    Richard <> writes:

    > Hi All,
    >
    > Tomcat servlets-examples directory includes an HellowWorld.html
    > example. How I am I supposed to run this to as a Tomcat example?
    >
    > I've got Tomcat running, as evidenced by the "Apache Tomcat/5.5.12"
    > webpage displayed in my Firefox browser at address http://localhost:8080/
    >
    > Double-clicking HellowWorld.html
    > displays a webpage with the heading "Source Code for HelloWorld
    > Example" followed, of course, by HellowWorld.html's text beautifully
    > color coded.
    >
    > My configuration:
    > WinXP-Pro/SP2, Ruby 1.8.2-15, Rails 1.1.6, Gem 0.9, MySQL 5.0.27-nt,
    > SciTE 1.72,
    > FireFox 2.0.0.1, IE 7.0, OE 6.0, MS Office 2003 SP2,
    > Java JVM 1.5.0_11-b03, Apache Tomcat/5.5.12,
    > AVG-Free 7.5.430, Prevx1 2.0.2.23, Startup Cop Pro 2.03
    >
    > TIA,
    > Richard


    The simple answer is to use the menu options. From the
    "Welcome Page" @ localhost:8080, you should see an examples box/menu
    on the left side of the screen which will walk you through all the
    examples.

    I think it's worth mentioning that if you want the know the url for
    a particular example, you can take a look inside WEB-INF/web.xml for
    that web application. In this case, a search for the
    HelloWorldExample class matches a servlet with the name
    "HelloWorldExample", which is then mapped to the url
    /servlet/HelloWorldExample . So you can go directly to
    http://localhost:8080/servlet/HelloWorldExample

    Hope that helps,
    Carl.
     
    Carl, May 30, 2007
    #2
    1. Advertising

  3. Richard

    Carl Guest

    Carl <> writes:
    > I think it's worth mentioning that if you want the know the url for
    > a particular example, you can take a look inside WEB-INF/web.xml for
    > that web application. In this case, a search for the
    > HelloWorldExample class matches a servlet with the name
    > "HelloWorldExample", which is then mapped to the url
    > /servlet/HelloWorldExample . So you can go directly to
    > http://localhost:8080/servlet/HelloWorldExample


    Doh!, that should have been:
    http://localhost:8080/servlets-examples/servlet/HelloWorldExample
    as setup by default on 5.5 .

    >
    > Hope that helps,
    > Carl.
     
    Carl, May 30, 2007
    #3
  4. Richard

    Richard Guest

    On May 30, 2:19 pm, Carl <> wrote:
    > Carl <> writes:
    > > I think it's worth mentioning that if you want the know the url for
    > > a particular example, you can take a look inside WEB-INF/web.xml for
    > > that web application. In this case, a search for the
    > > HelloWorldExample class matches a servlet with the name
    > > "HelloWorldExample", which is then mapped to the url
    > > /servlet/HelloWorldExample . So you can go directly to
    > >http://localhost:8080/servlet/HelloWorldExample

    >
    > Doh!, that should have been:http://localhost:8080/servlets-examples/servlet/HelloWorldExample
    > as setup by default on 5.5 .
    >
    >
    >
    > > Hope that helps,
    > > Carl.


    Hi Carl,

    >http://localhost:8080/servlet/HelloWorldExample


    Thanks! That was great help ... it worked as advertised both with
    Firefox 2 and IE 7.

    > I think it's worth mentioning ...


    Absolutely. This is even better! I opened
    Tomcat 5.5\webapps\servlets-examples\WEB-INF\web.xml
    in Oxygen, an XML editor, and followed your excellent analysis.

    I'm just have one question:
    - the original example was helloworld.html
    - searching for that fails
    - dropping the extension turns up
    - <servlet-name>HelloWorldExample</servlet-name>

    What gives us assurance the "helloworld.html" is related to the
    "HelloWorldExample" servlet (aside from just trying it)?

    Thank you again for your excellent response. I regret having to pile
    on one more question.

    Best wishes,
    Richard
     
    Richard, May 30, 2007
    #4
  5. Richard

    Carl Guest

    Richard <> writes:

    > On May 30, 2:19 pm, Carl <> wrote:
    > > Carl <> writes:
    > > > I think it's worth mentioning that if you want the know the url for
    > > > a particular example, you can take a look inside WEB-INF/web.xml for
    > > > that web application. In this case, a search for the
    > > > HelloWorldExample class matches a servlet with the name
    > > > "HelloWorldExample", which is then mapped to the url
    > > > /servlet/HelloWorldExample . So you can go directly to
    > > >http://localhost:8080/servlet/HelloWorldExample

    > >
    > > Doh!, that should have been:http://localhost:8080/servlets-examples/servlet/HelloWorldExample
    > > as setup by default on 5.5 .
    > >
    > >
    > >
    > > > Hope that helps,
    > > > Carl.

    >
    > Hi Carl,
    >
    > >http://localhost:8080/servlet/HelloWorldExample

    >
    > Thanks! That was great help ... it worked as advertised both with
    > Firefox 2 and IE 7.
    >
    > > I think it's worth mentioning ...

    >
    > Absolutely. This is even better! I opened
    > Tomcat 5.5\webapps\servlets-examples\WEB-INF\web.xml
    > in Oxygen, an XML editor, and followed your excellent analysis.
    >
    > I'm just have one question:
    > - the original example was helloworld.html
    > - searching for that fails
    > - dropping the extension turns up
    > - <servlet-name>HelloWorldExample</servlet-name>
    >
    > What gives us assurance the "helloworld.html" is related to the
    > "HelloWorldExample" servlet (aside from just trying it)?
    >
    > Thank you again for your excellent response. I regret having to pile
    > on one more question.
    >
    > Best wishes,
    > Richard


    Hi Richard,

    In this example, the "helloworld.html" file is not actually related
    to the HelloWorldExample servlet. The "helloworld.html" file is a
    static html page that displays the source code for a servlet class
    named HelloWorld . To make matters more confusing, the actual
    servlet included in the examples with tomcat 5.5 is named
    "HelloWorldExample", not "HelloWorld", as shown in the example
    source.

    The thing to note here is that content in the root of the web-app
    directory ('tomcat-home/webapps/servlets-examples/') can be accessed
    directly by the client. i.e. in order to view
    servlets-examples/helloworld.html you just point your browser to
    http://localhost:8080/servlets-examples/helloworld.html
    and tomcat will serve it to you. In this example, you receive
    a plain old html page, not a jsp page or servlet output.

    The example servlet, however, is accessed
    using the url-pattern shown in the web.xml file. In this case, any
    request to a url that matches the pattern
    "/servlet/HelloWorldExample" will be sent to a servlet named
    HelloWorldExample. The source for this servlet should be found in:
    servlet-examples/WEB-INF/classes/HelloWorldExample.java
    This is the code that is called when you actually run the example.

    Hope that makes sense :\
    Carl.
     
    Carl, May 30, 2007
    #5
  6. Richard

    Richard Guest

    Hi Carl,

    > Hope that makes sense


    It sure does, though I'm going have to check out all the pieces, one
    by one.

    Thank you for such a clear and detailed explanation.

    Yours truly,
    Richard

    On May 30, 5:51 pm, Carl <> wrote:
    > Richard <> writes:
    > > On May 30, 2:19 pm, Carl <> wrote:
    > > > Carl <> writes:
    > > > > I think it's worth mentioning that if you want the know the url for
    > > > > a particular example, you can take a look inside WEB-INF/web.xml for
    > > > > that web application. In this case, a search for the
    > > > > HelloWorldExample class matches a servlet with the name
    > > > > "HelloWorldExample", which is then mapped to the url
    > > > > /servlet/HelloWorldExample . So you can go directly to
    > > > >http://localhost:8080/servlet/HelloWorldExample

    >
    > > > Doh!, that should have been:http://localhost:8080/servlets-examples/servlet/HelloWorldExample
    > > > as setup by default on 5.5 .

    >
    > > > > Hope that helps,
    > > > > Carl.

    >
    > > Hi Carl,

    >
    > > >http://localhost:8080/servlet/HelloWorldExample

    >
    > > Thanks! That was great help ... it worked as advertised both with
    > > Firefox 2 and IE 7.

    >
    > > > I think it's worth mentioning ...

    >
    > > Absolutely. This is even better! I opened
    > > Tomcat 5.5\webapps\servlets-examples\WEB-INF\web.xml
    > > in Oxygen, an XML editor, and followed your excellent analysis.

    >
    > > I'm just have one question:
    > > - the original example was helloworld.html
    > > - searching for that fails
    > > - dropping the extension turns up
    > > - <servlet-name>HelloWorldExample</servlet-name>

    >
    > > What gives us assurance the "helloworld.html" is related to the
    > > "HelloWorldExample" servlet (aside from just trying it)?

    >
    > > Thank you again for your excellent response. I regret having to pile
    > > on one more question.

    >
    > > Best wishes,
    > > Richard

    >
    > Hi Richard,
    >
    > In this example, the "helloworld.html" file is not actually related
    > to the HelloWorldExample servlet. The "helloworld.html" file is a
    > static html page that displays the source code for a servlet class
    > named HelloWorld . To make matters more confusing, the actual
    > servlet included in the examples with tomcat 5.5 is named
    > "HelloWorldExample", not "HelloWorld", as shown in the example
    > source.
    >
    > The thing to note here is that content in the root of the web-app
    > directory ('tomcat-home/webapps/servlets-examples/') can be accessed
    > directly by the client. i.e. in order to view
    > servlets-examples/helloworld.html you just point your browser tohttp://localhost:8080/servlets-examples/helloworld.html
    > and tomcat will serve it to you. In this example, you receive
    > a plain old html page, not a jsp page or servlet output.
    >
    > The example servlet, however, is accessed
    > using the url-pattern shown in the web.xml file. In this case, any
    > request to a url that matches the pattern
    > "/servlet/HelloWorldExample" will be sent to a servlet named
    > HelloWorldExample. The source for this servlet should be found in:
    > servlet-examples/WEB-INF/classes/HelloWorldExample.java
    > This is the code that is called when you actually run the example.
    >
    > Hope that makes sense :\
    > Carl.
     
    Richard, May 31, 2007
    #6
  7. Richard

    Richard Guest

    Hi Carl,

    It's starting to make sense to me, but I'm still in woods with at
    least one detail.

    > In this case, any request to a url that matches the pattern

    "/servlet/HelloWorldExample" will be sent to a servlet named
    HelloWorldExample.

    I gave Firefox the address http://localhost:8080/ and got the Apache
    Tomcat 5.5.12 home page, so Tomcat's running fine.

    But the address http://localhost:8080/servlet/HelloWorldExample gave
    me a status 404: The requested resource (/servlet/HelloWorldExample)
    is not available. (I tried a bunch of things to no avail: adding
    extensions, more of the path, etc. Maybe I should reinstall Tomcat in
    a path that does not have any spaces, e.g as "Tomcat 5.5" does.)

    The files HelloWorldExample.java and .class are in
    Tomcat 5.5\webapps\servlets-examples\WEB-INF\classes
    and the .java file defines HelloWorldExample
    as a public class that extends HttpServlet.

    BTW, http://localhost:8080/servlets-examples/helloworld.html still
    displays the servlet HelloWorldExample.java code as text.

    Can you guess where I'm going wrong. If you need more info, I'd be
    pleased to provide whatever you might think helpful in extracting me
    from this quagmire.

    Best wishes,
    Richard



    On May 30, 5:51 pm, Carl <> wrote:
    > Richard <> writes:
    > > On May 30, 2:19 pm, Carl <> wrote:
    > > > Carl <> writes:
    > > > > I think it's worth mentioning that if you want the know the url for
    > > > > a particular example, you can take a look inside WEB-INF/web.xml for
    > > > > that web application. In this case, a search for the
    > > > > HelloWorldExample class matches a servlet with the name
    > > > > "HelloWorldExample", which is then mapped to the url
    > > > > /servlet/HelloWorldExample . So you can go directly to
    > > > >http://localhost:8080/servlet/HelloWorldExample

    >
    > > > Doh!, that should have been:http://localhost:8080/servlets-examples/servlet/HelloWorldExample
    > > > as setup by default on 5.5 .

    >
    > > > > Hope that helps,
    > > > > Carl.

    >
    > > Hi Carl,

    >
    > > >http://localhost:8080/servlet/HelloWorldExample

    >
    > > Thanks! That was great help ... it worked as advertised both with
    > > Firefox 2 and IE 7.

    >
    > > > I think it's worth mentioning ...

    >
    > > Absolutely. This is even better! I opened
    > > Tomcat 5.5\webapps\servlets-examples\WEB-INF\web.xml
    > > in Oxygen, an XML editor, and followed your excellent analysis.

    >
    > > I'm just have one question:
    > > - the original example was helloworld.html
    > > - searching for that fails
    > > - dropping the extension turns up
    > > - <servlet-name>HelloWorldExample</servlet-name>

    >
    > > What gives us assurance the "helloworld.html" is related to the
    > > "HelloWorldExample" servlet (aside from just trying it)?

    >
    > > Thank you again for your excellent response. I regret having to pile
    > > on one more question.

    >
    > > Best wishes,
    > > Richard

    >
    > Hi Richard,
    >
    > In this example, the "helloworld.html" file is not actually related
    > to the HelloWorldExample servlet. The "helloworld.html" file is a
    > static html page that displays the source code for a servlet class
    > named HelloWorld . To make matters more confusing, the actual
    > servlet included in the examples with tomcat 5.5 is named
    > "HelloWorldExample", not "HelloWorld", as shown in the example
    > source.
    >
    > The thing to note here is that content in the root of the web-app
    > directory ('tomcat-home/webapps/servlets-examples/') can be accessed
    > directly by the client. i.e. in order to view
    > servlets-examples/helloworld.html you just point your browser tohttp://localhost:8080/servlets-examples/helloworld.html
    > and tomcat will serve it to you. In this example, you receive
    > a plain old html page, not a jsp page or servlet output.
    >
    > The example servlet, however, is accessed
    > using the url-pattern shown in the web.xml file. In this case, any
    > request to a url that matches the pattern
    > "/servlet/HelloWorldExample" will be sent to a servlet named
    > HelloWorldExample. The source for this servlet should be found in:
    > servlet-examples/WEB-INF/classes/HelloWorldExample.java
    > This is the code that is called when you actually run the example.
    >
    > Hope that makes sense :\
    > Carl.
     
    Richard, Jun 1, 2007
    #7
  8. Richard

    Richard Guest

    Hi Carl,

    I've made progress:
    - I upgraded to Tomcat 6.0.13
    - installed it in Apache\Tomcat_6.0 (no blanks in path!)
    - noted the Servlets Examples link on Tomcat's homepage
    - noted the Execute link for Hello World:
    - - http://localhost:8080/
    - - examples/servlets/
    - - servlet/HelloWorldExample
    - double-clicked that link

    That gave me a vanilla "Hello World!" page, i.e.
    - <title>Hello World!</title>
    - <h1>Hello World!</h1>
    and miscellaneous HTML.

    I'm still researching the how it all hooks together, especially the
    WEB-INF\web.xml. So no more questions for you (at least from me for
    you).

    Thanks for your help,
    Best wishes,
    Richard


    On May 30, 5:51 pm, Carl <> wrote:
    > Richard <> writes:
    > > On May 30, 2:19 pm, Carl <> wrote:
    > > > Carl <> writes:
    > > > > I think it's worth mentioning that if you want the know the url for
    > > > > a particular example, you can take a look inside WEB-INF/web.xml for
    > > > > that web application. In this case, a search for the
    > > > > HelloWorldExample class matches a servlet with the name
    > > > > "HelloWorldExample", which is then mapped to the url
    > > > > /servlet/HelloWorldExample . So you can go directly to
    > > > >http://localhost:8080/servlet/HelloWorldExample

    >
    > > > Doh!, that should have been:http://localhost:8080/servlets-examples/servlet/HelloWorldExample
    > > > as setup by default on 5.5 .

    >
    > > > > Hope that helps,
    > > > > Carl.

    >
    > > Hi Carl,

    >
    > > >http://localhost:8080/servlet/HelloWorldExample

    >
    > > Thanks! That was great help ... it worked as advertised both with
    > > Firefox 2 and IE 7.

    >
    > > > I think it's worth mentioning ...

    >
    > > Absolutely. This is even better! I opened
    > > Tomcat 5.5\webapps\servlets-examples\WEB-INF\web.xml
    > > in Oxygen, an XML editor, and followed your excellent analysis.

    >
    > > I'm just have one question:
    > > - the original example was helloworld.html
    > > - searching for that fails
    > > - dropping the extension turns up
    > > - <servlet-name>HelloWorldExample</servlet-name>

    >
    > > What gives us assurance the "helloworld.html" is related to the
    > > "HelloWorldExample" servlet (aside from just trying it)?

    >
    > > Thank you again for your excellent response. I regret having to pile
    > > on one more question.

    >
    > > Best wishes,
    > > Richard

    >
    > Hi Richard,
    >
    > In this example, the "helloworld.html" file is not actually related
    > to the HelloWorldExample servlet. The "helloworld.html" file is a
    > static html page that displays the source code for a servlet class
    > named HelloWorld . To make matters more confusing, the actual
    > servlet included in the examples with tomcat 5.5 is named
    > "HelloWorldExample", not "HelloWorld", as shown in the example
    > source.
    >
    > The thing to note here is that content in the root of the web-app
    > directory ('tomcat-home/webapps/servlets-examples/') can be accessed
    > directly by the client. i.e. in order to view
    > servlets-examples/helloworld.html you just point your browser tohttp://localhost:8080/servlets-examples/helloworld.html
    > and tomcat will serve it to you. In this example, you receive
    > a plain old html page, not a jsp page or servlet output.
    >
    > The example servlet, however, is accessed
    > using the url-pattern shown in the web.xml file. In this case, any
    > request to a url that matches the pattern
    > "/servlet/HelloWorldExample" will be sent to a servlet named
    > HelloWorldExample. The source for this servlet should be found in:
    > servlet-examples/WEB-INF/classes/HelloWorldExample.java
    > This is the code that is called when you actually run the example.
    >
    > Hope that makes sense :\
    > Carl.
     
    Richard, Jun 1, 2007
    #8
  9. Richard

    Carl Guest

    Richard <> writes:

    > Hi Carl,
    >
    > It's starting to make sense to me, but I'm still in woods with at
    > least one detail.
    >
    >> In this case, any request to a url that matches the pattern

    > "/servlet/HelloWorldExample" will be sent to a servlet named
    > HelloWorldExample.
    >
    > I gave Firefox the address http://localhost:8080/ and got the Apache
    > Tomcat 5.5.12 home page, so Tomcat's running fine.
    >
    > But the address http://localhost:8080/servlet/HelloWorldExample gave
    > me a status 404: The requested resource (/servlet/HelloWorldExample)
    > is not available. (I tried a bunch of things to no avail: adding
    > extensions, more of the path, etc. Maybe I should reinstall Tomcat in
    > a path that does not have any spaces, e.g as "Tomcat 5.5" does.)
    >
    > The files HelloWorldExample.java and .class are in
    > Tomcat 5.5\webapps\servlets-examples\WEB-INF\classes
    > and the .java file defines HelloWorldExample
    > as a public class that extends HttpServlet.
    >
    > BTW, http://localhost:8080/servlets-examples/helloworld.html still
    > displays the servlet HelloWorldExample.java code as text.
    >
    > Can you guess where I'm going wrong. If you need more info, I'd be
    > pleased to provide whatever you might think helpful in extracting me
    > from this quagmire.
    >
    > Best wishes,
    > Richard
    >
    >


    Hi Richard,

    Sorry for the late reply, I entirely missed this followup.
    I hope you've found the problem by now, but just in case...

    In your first example, you're simply missing the web application
    directory in your url. The url patterns in the web.xml file are
    going to be relative to the web application directory, not the
    tomcat directory for web applications (a bit confusing, i know...)
    in this case, the directory named "servlets-examples"

    http://localhost:8080/servlet/HelloWorldExample
    should have been
    http://localhost:8080/servlets-examples/servlet/HelloWorldExample

    Hope that helps,
    Carl.
     
    Carl, Jun 8, 2007
    #9
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. marcelino
    Replies:
    0
    Views:
    810
    marcelino
    Jan 29, 2004
  2. mojgan
    Replies:
    5
    Views:
    4,497
    William Brogden
    Jul 3, 2004
  3. Ryan
    Replies:
    2
    Views:
    460
    Paul H. van Rossem
    Nov 7, 2004
  4. baitelli
    Replies:
    0
    Views:
    343
    baitelli
    Aug 31, 2006
  5. Sam Roberts
    Replies:
    15
    Views:
    312
    Sam Roberts
    Feb 7, 2005
Loading...

Share This Page