Java Forum / General / June 2007
How to run a Tomcat example
Richard - 30 May 2007 14:53 GMT 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
Carl - 30 May 2007 18:52 GMT > Hi All, > [quoted text clipped - 18 lines] > 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 - 30 May 2007 19:19 GMT > 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 [quoted text clipped - 3 lines] > /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. Richard - 30 May 2007 21:25 GMT > > 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 [quoted text clipped - 9 lines] > > 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
Carl - 30 May 2007 22:51 GMT > > > 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 [quoted text clipped - 37 lines] > 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.
Richard - 31 May 2007 01:04 GMT 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
> > > > 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 [quoted text clipped - 65 lines] > Hope that makes sense :\ > Carl. Richard - 01 Jun 2007 00:44 GMT 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
> > > > 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 [quoted text clipped - 65 lines] > Hope that makes sense :\ > Carl. Carl - 08 Jun 2007 07:59 GMT > Hi Carl, > [quoted text clipped - 28 lines] > 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.
Richard - 01 Jun 2007 21:11 GMT 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
> > > > 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 [quoted text clipped - 65 lines] > Hope that makes sense :\ > Carl.
Free MagazinesGet these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...
|
|
|