Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Creating A New Context

Status
Not open for further replies.

aas1611

Programmer
Dec 14, 2001
184
DE
Hi!

I just start learning Jakarta Tomcat. My first assignment is to create a new context (called learning) under webapps directory. After following the instruction carefully, and copying a java class called IsItWorking into /learning/servlet, I ended up with a message that says this class can not be found, even though I put it in a correct directory.

On my browser, I typed:

I've made several trials, like putting this class one directory higher (/learning) and tried to open it with:

and still, it didn't work.

Is there some procedure I might overlook? What can cause this error message?

Please help! And thanks in advance...

Andre
 
1) Classes deployed under tomcat should be in packages.
2) They should either be archived into a jar file, and put into WEB-INF/lib, or put unjarred into WEB-INF/classes.
3) You must alter web.xml to map your servlet to a URL.

So if your class was in a package called acme.com, your would deploy it into TOMCAT_HOME/webapps/learning/WEB-INF/classes/acme/com

Then in web.xml, you should add the following :

Code:
        <servlet>
                <servlet-name>IsItWorking</servlet-name>
                <servlet-class>acme.com.IsItWorking</servlet-class>
                <load-on-startup>1</load-on-startup>
        </servlet>
        <servlet-mapping>
                <servlet-name>IsItWorking</servlet-name>
                <url-pattern>/servlet/IsItWorking</url-pattern>
        </servlet-mapping>

--------------------------------------------------
Free Java/J2EE Database Connection Pooling Software
 
I was not supposed to use the package for the first assignment or alter the web.xml (because it will be explained later). I was supposed to create the directory manually.

Anyway, I managed to make it work. It was the way I added the context under ContextAdmin. What I don't understand is, I put the IsItWorking.class under learning/WEB-INF/classes, then call it from my browser with this:


It works, even though my servlet folder is empty.

Does it have something to do with a configuration? If yes, which configuration is it (where I can see it)? If no, what then?

confused...

Andre
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top