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??
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\.....
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).
webapps | |shan | |WEB-INF contains classes and web.xml file 4. Place your files (servlet ,html, jsp )and restart. "done" 5.See that your servlet and helper class are placed inside classes folder always. "done" 6. refer your context by url given below http:\\localhost:8080\yourfolder\..... http:\\localhost:8080\shan\test
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 ]
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
William Brogden
,
Author and all-around good cowpoke
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