This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
    Bookmark Topic Watch Topic
  • New Topic

how to use the servlet in tomcat??

 
Tony Ge
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Report post to moderator
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??
 
Arun Boraiah
Ranch Hand
Posts: 233
  • Mark post as helpful
  • send pies
  • Report post to moderator
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
 
Tony Ge
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Report post to moderator
test successfully!!!
much thanx!!!
 
Oleksandr Karpus
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Report post to moderator
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 )
 
Mike Curwen
Ranch Hand
Posts: 3695
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
  • Report post to moderator
take out the word 'root'
 
pari pat
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Report post to moderator
Just wanna find the same
 
Oleksandr Karpus
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Report post to moderator
It's OK now.
Thanks Mike Curwen
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Report post to moderator
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 ]
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Report post to moderator
Got it!!!
 
Tony Ge
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Report post to moderator
may be you can delete the web.xml in the folder you created!!
try !!!
 
krish chandru
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Report post to moderator
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
Rancher
Posts: 13056
6
  • Mark post as helpful
  • send pies
  • Report post to moderator
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
 
Mike Curwen
Ranch Hand
Posts: 3695
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
  • Report post to moderator
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.
 
    Bookmark Topic Watch Topic
  • New Topic