Wrox Programmer Forums
|
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 September 13th, 2004, 06:13 PM
Authorized User
 
Join Date: Sep 2004
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
Default Tomcat server

I have installed Tomcat and it DOES get started (i.e. it displays the Tomcat page when I use the URL http://localhost). Questions about URL's for Tomcat:

1) http://localhost
How does my browser (Safari) know enough to look in the Jakarta ROOT directory for the index.html file?

2) http://localhost/testApp/Hello.html -- displays Hello.
How does Safari know enough to find my testApp directory in the jakarta webapps directory?

3) http://localhost/server/HelloServlet -- doesn't work for me.
I assume that /server/ is telling Tomcat to use server.xml -- is that correct?
How does the browser know where server.xml is, and how does it find the directory containing HelloServlet.class?

Thanks for the help.

ms



 
Old September 13th, 2004, 11:53 PM
Friend of Wrox
 
Join Date: Jul 2004
Posts: 345
Thanks: 0
Thanked 1 Time in 1 Post
Send a message via MSN to gokul_blr Send a message via Yahoo to gokul_blr
Default

Along with that http://localhost you should also use the port no. http://localhost:8080/

will list out the directories

 
Old September 14th, 2004, 12:09 AM
Friend of Wrox
 
Join Date: Jul 2004
Posts: 345
Thanks: 0
Thanked 1 Time in 1 Post
Send a message via MSN to gokul_blr Send a message via Yahoo to gokul_blr
Default

• Move the files to a subdirectory that matches the
intended package name
– e.g. Use codecamp as the package name for all the
java classes in this course.
– the class files need to go in a subdirectory called
codecamp.
• Insert a package statement in the class file
– E.g., top of HelloServlet.java:
– package codecamp;
• Set CLASSPATH to top-level directory which contains
codecamp directory .
• Include package name in
URLhttp://localhost:port/servlet/codecamp.HelloServlet

 
Old September 14th, 2004, 12:12 AM
Friend of Wrox
 
Join Date: Jul 2004
Posts: 345
Thanks: 0
Thanked 1 Time in 1 Post
Send a message via MSN to gokul_blr Send a message via Yahoo to gokul_blr
Default

You can get help from following pdf file (JSP & Servlets)

http://java.sun.com/j2ee/1.4/download.html#tutorial

 
Old September 14th, 2004, 06:51 AM
Friend of Wrox
 
Join Date: Jul 2004
Posts: 204
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hello and good luck, youre gonna need it:-)

New to this myself so may not be the best advice around...

1) Local host (as are most things in tomcat) is defined in server.xml.
Have a play with it AFTER you create a backup copy.

2) I think that tomcat auto detects webapps if they have a WEB-INF folder containing a web.xml for the app. I had a problem setting up my app, then tomcat automatically found it.

3) If servlets arent working try un commenting the following in Tomcat5\conf\web.xml

<servlet>
  <servlet-name>invoker</servlet-name>
  <servlet-class>
    org.apache.catalina.servlets.InvokerServlet
  </servlet-class>
  <init-param>
    <param-name>debug</param-name>
    <param-value>0</param-value>
  </init-param>
  <load-on-startup>2</load-on-startup>
</servlet>

And again, un-comment:

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

The line <url-pattern>/servlet/*</url-pattern> tells tomcat to route anything with /servlet/ in the path to your servlets folder.




 
Old September 14th, 2004, 11:21 AM
Authorized User
 
Join Date: Sep 2004
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks for your input.
Uncommenting the web.xml code (angry cat) did NOT work. Here's what I had tried:
1) compiled HelloServlet.java (successfully) and put the class output into Tomcat5/webapps/ROOT/WEB-INF/classes
2) the URL http://localhost/servlet/HelloServlet gave me a 404 ("The requested URL /servlet/HelloServlet was not found on this server") error

I can't get /servlet/ to work. Must have my directories wrong.
Any ideas?

One very confusing thing to me is the many same-named directories (e.g. WEB-INF). I'm never quite sure which ones to use.

Thanks again for your input.

ms

 
Old September 14th, 2004, 01:24 PM
Friend of Wrox
 
Join Date: Jul 2004
Posts: 204
Thanks: 0
Thanked 0 Times in 0 Posts
Default

See what I mean about the luck thing!

Have you got the sample jsp and servlets to work?

If you go back to the tomcat home page at localhost, in the left margin about half way down are both jsp and servlet examples. If the servlet examples dont work, there is something else amis, like have you set the java class path?

If the servlet examples do work, look for the folder that these examples are in and put yours in there also.



 
Old September 14th, 2004, 02:55 PM
Authorized User
 
Join Date: Sep 2004
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
Default

To gokul bir:

I tried unsuccessfully to run a servlet in a package, as you suggested. This is what I did:
1) created a directory, coreservlets, in jakarta-tomcat-5.0.27/webapps/ROOT/WEB-INF/classes
2) put HelloServlet2.class in that directory
3) set CLASSPATH to that directory
4) gave the browser the URL: http://localhost/servlet/coreservlets/HelloServlet2
(BTW, I have set the port to 80 in servlet.xml)

The browser tells me URL NOT FOUND.

I can run html files, I can compile java servlets, but I am unable to run them.
I'm somehow using the directories wrong.

ms


 
Old September 14th, 2004, 03:54 PM
Friend of Wrox
 
Join Date: Jul 2004
Posts: 204
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hello again,

I think you were on track the first time.
I have exactly the same setup for my servlets, in the same folder:

\webapps\ROOT\WEB-INF\classes

 and with the same /servlet/ in the url:

http://localhost/servlet/PostMultiServlet

You DO NOT need to put servlets in a package, though I think you do have to put beans in a package, at least thats how I got beans to work.

Do the tomcat examples work?

 
Old September 14th, 2004, 03:56 PM
Friend of Wrox
 
Join Date: Jul 2004
Posts: 204
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I tak eit you restarted tomcat after changing web.xml?






Similar Threads
Thread Thread Starter Forum Replies Last Post
using tomcat as an application server deepak Apache Tomcat 0 July 27th, 2008 01:53 PM
executing a jsp program on tomcat server sushant2002 JSP Basics 2 August 28th, 2007 10:54 PM
Help with getting Tomcat to server php sazzie BOOK: Professional Apache Tomcat 0 March 16th, 2007 07:23 AM
how to register servlets with Tomcat 5.59 server urstruly90 Apache Tomcat 0 July 21st, 2005 03:50 AM
apache virtual server, mod_jk, tomcat 5 curiousmind Apache Tomcat 1 May 17th, 2005 09:44 AM





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