aspose file tools*
The moose likes Servlets and the fly likes Executing Servlet File using Tomcat Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Executing Servlet File using Tomcat" Watch "Executing Servlet File using Tomcat" New topic
Author

Executing Servlet File using Tomcat

Mahera Shaikh
Greenhorn

Joined: Jan 27, 2011
Posts: 6
I m completely new the Servlet, I m unable to run the servlet file using the URL
http://localhost:8080...
I instld Tomcat 7.0, Made a source class file..
but dnt know how to execute file..
Please ne one can provide me step by step procedure to run the Servlet file..
Please....
Rajani Gummadi
Ranch Hand

Joined: Dec 17, 2010
Posts: 48
Below are the steps you need to follow.

1) Write the servlet class.
2) Configure web.xml or through some annotations based on the version you are using.
3) build war file.
4) deploy the war file
5) invoke the servlet like http://localhost:8080/<<app/contextname>>/<<URL pattern>>

If you had looked into FAQS session, you would certainly find examples on how to setup the web application or through google

All the best.
Vishal Hegde
Ranch Hand

Joined: Aug 01, 2009
Posts: 1055

Click here

Welcome to Javaranch Mahera i also dont know much about servlets but did a little google search


http://www.lifesbizzare.blogspot.com || OCJP:81%
Mahera Shaikh
Greenhorn

Joined: Jan 27, 2011
Posts: 6
Thnx Rajni G Sir..
But i need it in quiet clarified language...
Each step with exaplanation....


Please do post with detailed explanation...
Rajani Gummadi
Ranch Hand

Joined: Dec 17, 2010
Posts: 48
Mahera Shaikh wrote:Thnx Rajni G Sir..
But i need it in quiet clarified language...
Each step with exaplanation....


Please do post with detailed explanation...


Hi Mahera, have you considered looking at the example which Vishal provided or the "HelloWorld" servlet given in the link provided? What are the issues you are facing in understanding those examples? Please do not hesitate to ask your questions, but I would still ask you to look into those links before.
Mahera Shaikh
Greenhorn

Joined: Jan 27, 2011
Posts: 6
I realy dint get so asking...
Please do help me...
Wil b vry greatful...

Mahera Shaikh
Greenhorn

Joined: Jan 27, 2011
Posts: 6
Thnx vishal...
I tried with Rose India..
but getng a error report
File Not found...
Vishal Hegde
Ranch Hand

Joined: Aug 01, 2009
Posts: 1055

Hi Mahera,

Its ok if you call us by our names..You dont wanna mistakes by calling some lady Sir(unless you are pretty much sure about it)

File not found Exception.....hmmmm

Might be ....

File doesnot exists
Path must be wrong
Class path defined wrong
(well just my rough guesses)
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41574
    
  54
Mahera Shaikh wrote:I tried with Rose India..

Don't ever use that site - it's full of erroneous code, bad advice and bad practices.


Ping & DNS - my free Android networking tools app
Vishal Hegde
Ranch Hand

Joined: Aug 01, 2009
Posts: 1055

Ulf Dittmer wrote:
Mahera Shaikh wrote:I tried with Rose India..

Don't ever use that site - it's full of erroneous code, bad advice and bad practices.


what about its theory knowledge for basics??
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61064
    
  66

Vishal Hegde wrote:
Ulf Dittmer wrote:
Mahera Shaikh wrote:I tried with Rose India..

Don't ever use that site - it's full of erroneous code, bad advice and bad practices.


what about its theory knowledge for basics??

I agree with Ulf. It is not a good site. Teaching bad code and poor practices is not a good way to learn basics or anything else.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Vishal Hegde
Ranch Hand

Joined: Aug 01, 2009
Posts: 1055

Thank you Bear Bibeault ,Ulf Dittmer for letting me know
Mahera Shaikh
Greenhorn

Joined: Jan 27, 2011
Posts: 6
Ulf....
Please if you can provide me with a link thn i wil be vry greatful...
Many tricks many practises thn to cnt execute the servlet file...
Actuly dnt kno wher to store the class file nd how to cal it on the browser page...
Swastik Dey
Rancher

Joined: Jan 08, 2009
Posts: 1457
    
    6

Under you application root(context) directory, you should have a folder called WEB-INF, which should have another folder called classes. You should keep your class file under the classes folder. In addition to this you should have another file web.xml(deployment descriptor) which specifies the url mapping details for the servlet. This file should kept in WEB-INF folder.

For e.g. you have a servlet called MyServlet. The you should keep the MyServlet.class under WEB-INF\classes. Now you have to create your web.xml something like this


Save this as web.xml in WEB-INF folder. I assume your context folder name is mysite

Restart tomcat and try to execute like
http://localhost:8080/mysite/test


Swastik
Vijitha Kumara
Bartender

Joined: Mar 24, 2008
Posts: 3825

Mahera Shaikh wrote:... thn i wil be vry greatful...
Many tricks many practises thn to cnt execute the servlet file...
Actuly dnt kno wher to store the class file nd how to cal it

Again, please UseRealWords when posting...


SCJP 5 | SCWCD 5
[How to ask questions] [Twitter]
Mahera Shaikh
Greenhorn

Joined: Jan 27, 2011
Posts: 6
Thank you very much swastik...
I got the problem solved.....

Regards,
Mahera
Swastik Dey
Rancher

Joined: Jan 08, 2009
Posts: 1457
    
    6

Glad to be of some help.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Executing Servlet File using Tomcat