Need help with tomcat!

S

Steve Burrus

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

Aidan

Hi Steve

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

Does this help ....?


webapps
|
|-- ROOT
| |-- WEB-INF
| | `-- web.xml
| |-- index.jsp
| |-- jakarta-banner.gif
| |-- tomcat-power.gif
| `-- tomcat.gif
|-- admin.xml
|-- friendbook-jsp
| |-- META-INF
| | `-- MANIFEST.MF
| |-- WEB-INF
| | |-- c.tld
| | |-- classes
| | | `-- org
| | | `-- infohazard
| | | `-- friendbook
| | | |-- ctl
| | | | |-- ChangePassword.class
| | | | |-- ChangePasswordSubmit.class
| | | | |-- ControllerAuth.class
| | | | |-- ControllerErrorable.class
| | | | |-- Edit.class
| | | | |-- EditSubmit.class
| | | | |-- Friends.class
| | | | |-- Gatekeeper.class
| | | | |-- LoginSubmit.class
| | | | |-- Logout.class
| | | | |-- Protected.class
| | | | `-- SignupSubmit.class
| | | `-- data
| | | |-- Address.class
| | | |-- Friend.class
| | | `-- FriendBook.class
| | |-- lib
| | | |-- commons-beanutils.jar
| | | |-- commons-collections.jar
| | | |-- jdom.jar
| | | |-- jstl.jar
| | | |-- maverick.jar
| | | `-- standard.jar
| | |-- maverick.xml
| | `-- web.xml
| |-- changePassword.jsp
| |-- default.jsp
| |-- edit.jsp
| |-- friends.jsp
| |-- loginFailed.jsp
| |-- loginForm.jsp
| |-- loginRequired.jsp
| |-- signup.jsp
| |-- stylesheet.css
| |-- trimInside.jsp
| |-- trimOutside.jsp
| `-- 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.
 
P

Phil Hanna

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.

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)
 
S

steve r. burrus

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!

***********************************************************************************************
 
M

Markku

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?
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,431
Messages
2,571,679
Members
48,796
Latest member
Greg L.

Latest Threads

Top