Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / February 2004

Tip: Looking for answers? Try searching our database.

Need help with tomcat!

Thread view: 
Steve Burrus - 27 Feb 2004 00:10 GMT
Could someone/somebody please
help me out with the whole package structure for tomcat? I would LOVE to

be able to see a servlet in a folder other than the usual
"C:\jakarta-tomcat-5.0.*\webapps\ROOT\WEB-INF\classes", and I always
specify the folder where I want the servlet class to go in the package
statement at the top of every servlet source file, but alas, I always
get the old 404 server error page whenever I put the servlet class file
into a folder other than the usual "....\ROOT\WEB-INF\classes" folder!!!

Can you please help me with this problem?                  Thanx.
Aidan - 27 Feb 2004 07:04 GMT
Hi Steve

> Could someone/somebody please
> help me out with the whole package structure for tomcat?

Does this help ....?

webapps

|-- ROOT
|   |-- WEB-INF
[quoted text clipped - 52 lines]
|   `-- welcome.jsp
|-- friendbook-jsp.war
`-- manager.xml

<!-- heavily edited -->
<web-app>
 <servlet>
    <servlet-name>dispatcher</servlet-name>
   <servlet-class>
       org.infohazard.maverick.Dispatcher
   </servlet-class>

   <servlet-mapping>
               <servlet-name>dispatcher</servlet-name>
               <url-pattern>*.m</url-pattern>
   </servlet-mapping>

   <welcome-file-list>
               <welcome-file>default.jsp</welcome-file>
    </welcome-file-list>
</web-app>

A.
Phil Hanna - 28 Feb 2004 05:16 GMT
>Could someone/somebody please
>help me out with the whole package structure for tomcat? I would LOVE to
[quoted text clipped - 7 lines]
>
>Can you please help me with this problem?                  Thanx.

Steve, I think we're confusing packages, webapp names, and directory
trees.  Your problem has nothing to do with the Tomcat directory
structure.  The "package" part of the directory structure doesn't
start until you get down *below* the \ROOT\WEB-INF\classes folder.

If you want another web application other than the default (ROOT), a
simple way to do it is to create a directory under webapps, e.g.

...\webapps\MyApp\WEB-INF\classes

and then put your classes there.  If "MyServlet" looks like this:

  package com.steve.myapp;
     ...
  public class MyServlet extends HttpServlet {
     ...
  }

then the class should be located at

...\webapps\MyApp\WEB-INF\classes\com\steve\myapp\MyServlet.class

You then need to tell Tomcat what URL you want to use for the servlet.
The "MyApp" application needs a deployment descriptor (web.xml)
located in it's WEB-INF directory:

...\webapps\MyApp\WEB-INF\web.xml

that contains at least the following:

<?xml version="1.0"?>

<!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>MyServlet</servlet-name>
     <servlet-class>com.steve.myapp.MyServlet</servlet-class>
  </servlet>

  <servlet-mapping>
     <servlet-name>MyServlet</servlet-name>
     <url-pattern>/MyServlet</url-pattern>
  </servlet-mapping>

</web-app>

Note that the url pattern is relative to the top of the web
application.

You will then be able to invoke your servlet from

http://localhost:8080/MyApp/MyServlet

(using the appropriate host name and port number, if not 80)

--
Phil Hanna
Author of JSP 2.0: The Complete Reference
http://www.philhanna.com
steve r. burrus - 28 Feb 2004 20:45 GMT
Hi there, phil, this is steve Burrus, and I wanted to first say or tell
u that it is indeed a DISTINCT PRIVILEDGE to be responded back to by
such a "distinguished author" as yourself!! :) So, the main question
that I have for you is : In looking at yer explanation of package
structure, I was just wondering if it's really necessary to create these
3 sub-folders under "...\webapps\MyApp\WEB-INF\classes" as you did :
"com.steve.myapp", and NOT maybe just create only 1 folder, and then
reference that in the package statement thusly : "package [newfolder];"
at the top of my servlet file??? And also, I have for a long time now
wondered about why exactly it's neccessary (or is it?) to create either
a "com" or an "org" folder as the top-level folder under
"WEB-INF\classes"? Okay then, thanx for your time!

***********************************************************************************************

>>Could someone/somebody please
>>help me out with the whole package structure for tomcat? I would LOVE to
[quoted text clipped - 71 lines]
> Author of JSP 2.0: The Complete Reference
> http://www.philhanna.com
Markku - 28 Feb 2004 21:06 GMT
> at the top of my servlet file??? And also, I have for a long time now
> wondered about why exactly it's neccessary (or is it?) to create either
> a "com" or an "org" folder as the top-level folder under
> "WEB-INF\classes"? Okay then, thanx for your time!

That's how the "package" system works in Java.
Package "com.myclasses" includes some classes and
files are in the folder ../com/myclasses/

And why it is so? If you got two (or more) classes with
same name like java.sql.Date and java.util.Date
you can't put them in the same folder can you?

Signature

Markku



Free Magazines

Get 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 ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.