This week's book giveaway is in the Cloud/Virtualization forum.
We're giving away four copies of Pipeline as Code and have Mohamed Labouardy on-line!
See this thread for details.
Win a copy of Pipeline as Code this week in the Cloud/Virtualization forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Rob Spoor
  • Henry Wong
  • Liutauras Vilda
Saloon Keepers:
  • Tim Moores
  • Carey Brown
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
Bartenders:
  • Frits Walraven
  • Himai Minh
  • Jj Roberts

Tomcat with servlet

 
Ranch Hand
Posts: 518
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I need to run my servlet program through tomcat.I dont know where to put the servlet.java file in tomcat directory.I am working in linux.I have installed apache-tomcat-5.5.26 in /usr/local.I have set the classpath in etc/profile as export CLASSPATH=$CLASSPATH:/usr/local/apache-tomcat-5.5.26/common/lib/servlet-api.jar.
After this where should i put my servlet.java .I dont know the procedures.please anyone assist me.

Thanks.
 
Rancher
Posts: 43024
76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is servlet.java the source to a servlet? If so, you need to compile it first, and then place the class file into the WEB-INF/classes directory of your web application. Your web application would typically consist of a directory underneath the "webapps" directory in the main Tomcat installation directory.

An introduction to servlets, JSPs and Tomcat can be found here.
[ March 29, 2008: Message edited by: Ulf Dittmer ]
 
preethi Ayyappan
Ranch Hand
Posts: 518
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks ulf, servlet.java is my source file. I have compiled it and the class file is also created.can i have my source file anywhere?


and then place the class file into the WEB-INF/classes directory of your web application


here web application means?I have to create a folder with any name?or is it inside webapps defaultly when tomcat is installed.please tell me in detail.
 
Ranch Hand
Posts: 1325
Android Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Tomcat and the Tomcat Web Application Directory Structure
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, your source file can be anywhere (including nowhere).
Tomcat doesn't do anything with your Java source files.

You need to create a folder for your application under tomcat/webapps.
You can name it anything you like (say 'myApp' for this discussion).
Inside that folder, you need another one named WEB-INF (case sensitive).
Inside WEB-INF, you need to create a folder named 'classes'.
The classes directory is where your package directory structure goes.
You class files go in the proper package folders.

Example:


A real quick way to get a sample, 'Hello, World' application with a proper directory structure and deployment descriptor up and running is to download our SimpleServlet.war example to your webapps directory. Tomcat will unpack this war file and deploy the application for you.

You can find this example in our CodeBarn
See:
http://faq.javaranch.com/java/CodeBarnSimpleServlet
[ March 29, 2008: Message edited by: Ben Souther ]
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Muhammad Saifuddin,

Thank you for providing that link.
Unfortunately, it is not exactly correct.
There are several directories listed that do not conform with the servlet spec and wouldn't work in a default Tomcat install (WEB-INF/help, WEB-INF/logs, etc).

It could be that those directories are specific to a particular application or project.
 
Muhammad Saifuddin
Ranch Hand
Posts: 1325
Android Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Unfortunately, it is not exactly correct.
There are several directories listed that do not conform with the servlet spec and wouldn't work in a default Tomcat install (WEB-INF/help, WEB-INF/logs, etc).



Thanks Ben, to point me (Servlet spec) for the right track.

Thanks again.
 
I child proofed my house but they still get in. Distract them with this tiny ad:
SKIP - a book about connecting industrious people with elderly land owners
https://coderanch.com/t/skip-book
reply
    Bookmark Topic Watch Topic
  • New Topic