if the test.java were a servlet and can be browsen in :http://localhost:8080/hello/test hello is the directory under :tomcat_home/webapps/root where should I put the test.java in ?? or how i sould modify the tomcat's servlert config??

Post by:Arun Boraiah
, Ranch Hand

Feb 19, 2002 04:45:00

Hi, Assuming that you are new to tomcat. I am about to give you solution. 1. place the test servlet inside classes folder found in \ROOT\WEB-INF\classes(if your test servlet is having a package, comment it for testing). 2. call this test servlet http://localhost:8080/root/servlet/test This should work.

But you better creat a context similar to root. For running your servlet.To achive that do the following steps. 1 .create a folder of any name inside "webapps "folder of tomcat. 2. map this in server.xml found in <tomcat_home>/conf folder(i.e, <Context path="/examples" docBase="webapps/examples" crossContext="false" debug="0" reloadable="true"/> copy this tag inside this file and replace "examples" by the folder name you have created) 3. see that folder created contains web-inf and classes folder and web.xml file similar to root context (make a copy of web.xml from root context if you want). 4. Place your files (servlet ,html, jsp )and restart. 5.See that your servlet and helper class are placed inside classes folder always. 6. refer your context by url given below http:\\localhost:8080\yourfolder\.....

-arun

Post by:Tony Ge
, Greenhorn

Feb 19, 2002 07:47:00

test successfully!!! much thanx!!!

Post by:Oleksandr Karpus
, Greenhorn

Feb 19, 2002 14:42:00

Hi Arun Boraiah It does not help me! I follow your or M.Hall instructions "If you get compilation errors, go back and check your CLASSPATH settings (see the earlier section on this topic)--you most likely erred in listing the location of the JAR file that contains the servlet classes (i.e.,install_dir/common/lib/servlet.jar). Once you compile HelloServlet.java, put HelloServlet.class in install_dir/webapps/ROOT/WEB-INF/classes. After compiling the code, access the servlet with the URL http://localhost/servlet/HelloServlet (or http://localhost:8080/servlet/HelloServlet or http://127.0.0.1:8080/root/servlet/helloServlet if you chose not to change the port number as described earlier). you should get a simple HTML page that says "Hello". If this URL fails but the test of the server itself succeeded, you probably put the class file in the wrong directory. " My HelloServlet.java is in C:\Program Files\Apache Tomcat 4.0\webapps\ROOT\WEB-INF\classes. I compile HelloServlet.java from TextPad. Always have reply like: "Apache Tomket/4.0.2 - HTTP Status 404 -/root/servlet/helloServlet type Status report message /root/servlet/helloServlet description The requested resource (/root/servlet/helloServlet ) is not available." If call it http://localhost:8080/root/servlet/helloservlet have: An error has occurred processing the request... Sasha SCJP2 ( Java is my hobby )

Hello Arun I followed ur instructions but was not successful But you better creat a context similar to root. For running your servlet.To achive that do the following steps. 1 .create a folder of any name inside "webapps "folder of tomcat. --created "shan"-- 2. map this in server.xml found in <tomcat_home>/conf folder(i.e, <Context path="/examples" docBase="webapps/examples" crossContext="false" debug="0" reloadable="true"/> copy this tag inside this file and replace "examples" by the folder name you have created) I did'nt find as above <!-- Tomcat Examples Context --> <Context path="/examples" docBase="examples" debug="0" reloadable="true"> I changed examples to "shan"

3. see that folder created contains web-inf and classes folder and web.xml file similar to root context (make a copy of web.xml from root context if you want).

I get this error type Status report message /shan/test description The requested resource (/shan/test ) is not available." what is the problem??? [ February 20, 2002: Message edited by: shan java ]

Post by:Anonymous
, Ranch Hand

Feb 21, 2002 12:57:00

Got it!!!

Post by:Tony Ge
, Greenhorn

Feb 21, 2002 17:25:00

may be you can delete the web.xml in the folder you created!! try !!!

Post by:krish chandru
, Ranch Hand

Feb 21, 2002 21:39:00

Hi i want to write a servlet that just does initialisation work. It is not called by any other page, but it is directly invoked in the url and the application flows subsequently. i presume i should not write the initialisation code in doGet or doPost. am i right ? if yes how else can i do it ? krish chandru

Post by:William Brogden
, Rancher

Feb 22, 2002 07:53:00

Servlet initialization belongs in the init() method. I don't understand what you mean by

It is not called by any other page, but it is directly invoked in the url and the application flows subsequently.

Are you going to direct requests to this servlet or not? You can certainly make a servlet that gets loaded on startup and you can control the order in which the startup servlets get initialized. Bill

Post by:Mike Curwen
, Ranch Hand

Feb 22, 2002 08:25:00

By my count, this is the fourth time this thread has been re-used, for a different question.

So I'm closing it now. If anyone wants to continue a topic, start your own thread. Thanks.