Forums Register Login

how to use the servlet in tomcat??

+Pie Number of slices to send: Send
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??
+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
test successfully!!!
much thanx!!!
+Pie Number of slices to send: Send
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 )
+Pie Number of slices to send: Send
take out the word 'root'
+Pie Number of slices to send: Send
Just wanna find the same
+Pie Number of slices to send: Send
It's OK now.
Thanks Mike Curwen
+Pie Number of slices to send: Send
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 ]
+Pie Number of slices to send: Send
Got it!!!
+Pie Number of slices to send: Send
may be you can delete the web.xml in the folder you created!!
try !!!
+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
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.
"Don't believe every tiny ad you see on the internet. But this one is rock solid." - George Washington
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


Reply locked
This thread has been viewed 2541 times.
Similar Threads
problem with mapping using servletrunner
How container recognizes a request for servlet
Servlet is running after tomcat is stopped.
problem in running a servlet
Servlet Basic Error !!
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 18, 2024 23:03:19.