File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes Not Found Error Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Not Found Error" Watch "Not Found Error" New topic
Author

Not Found Error

meena latha
Ranch Hand

Joined: Jan 24, 2005
Posts: 219
Hi all.
I worte a small program using servlet and was trying to call the servlet from the browser window.When i did that i am getting an erroe saying that servelet is not found.


In my web.xml



In my url
http://localhost:8080/MyProject/MyServlet.
where MyProject is my Project name.

When i did this i am getting error saying /MyProject/MyServlet not found.

Should i need to make any chance in my URL or anywhere else.
Thanks in advance.
Sharad Agarwal
Ranch Hand

Joined: Sep 11, 2002
Posts: 167
Originally posted by ramya jp:

In my web.xml



In my url
http://localhost:8080/MyProject/MyServlet.
where MyProject is my Project name.



You need a URL mapping in your web.xml, something like this:


Not wanting to open a can of worms, suffice it to say that some containers allow using the servlet's class in the URL. But such practice is strongly discouraged. Stick with the spec which requires an explicit URL mapping.


Alco-Haul: We move spirits.
Demented Deliberations of a Dilettante
satishkumar janakiraman
Ranch Hand

Joined: May 03, 2004
Posts: 334
Hi,

In your code, there is no Package name. Your 1st line in the code should be

Next URL Mapping is missing in your web.xml.

Try this.
bye for now
sat
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61451
    
  67



Why in the name of heaven would you override these methods to return null?
[ July 29, 2005: Message edited by: Bear Bibeault ]

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
meena latha
Ranch Hand

Joined: Jan 24, 2005
Posts: 219
Hi

Bear as i have implemented Servlet interface i need to override all the method in that interface.

The program i have written is an example from a developer guide book.
In that they have not used url mapping.

The web.xml mapping given in the book is


Sorry i missed to type the package name in the beginning.

In the book they have called the servlet using the below url

http://localhost:8080/MyProject/servlet/MyServlet.

I tried to call my servlet using the above url also.But with no result.

Can anybody work out this example and let me know whether it is working or not.

Thanks.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61451
    
  67

Bear as i have implemented Servlet interface i need to override all the method in that interface.


To write a servlet you do not directly implement the servlet interface, but rather extend the HttpServlet class.
meena latha
Ranch Hand

Joined: Jan 24, 2005
Posts: 219
Bear i know that we can use HttpServlet class directly.
But i wanted to try using Servlet interface and call my servlet directly without an URL mapping.

I am concerned my i am not able to call my servlet using the url

http://localhost:8080/MyProject/servlet/MyServlet.
Where MyProject is my folder name.
MyServlet is my servlet's name.

And the book say to use servlet/MyServlet to call my servlet.

It will be great if anybody can try this out and let me know the issue.

Thanks.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61451
    
  67

But i wanted to try using Servlet interface and call my servlet directly without an URL mapping.


These two things have nothing whatsoever to do with each other.
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Once you add a servlet mapping to your deployment descriptor (web.xml) you will be able to call your servlet.

Containers used to allow you to call servlets by putting the servlet classname in the URL (Tomcat did this with an invoker servlet which is still there but commented out in the the config files). Most have moved away from this practice as it has proven to be a bad idea.

See why here:
http://faq.javaranch.com/view?InvokerServlet

I have a site with lots of servlet example applications that have mapped servlets:
http://simple.souther.us
SimpleServlet shows how map a servlet.


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
meena latha
Ranch Hand

Joined: Jan 24, 2005
Posts: 219
Thanks for all you responses.
I too understand that it is a bad practise to call the servlet name directly,but just was curious why it was not working.
Any how all your responses are appreciated.

Thanks.
Parag Ballal
Greenhorn

Joined: Jul 28, 2005
Posts: 27
Approach 1:
What is the classpath set for server?
If server classpath is set to include "<complete_path>/MyProject" and
if MyServlet.class file is kept under "<complete_path>/MyProject/com/its/serv" directory
then you should be able to access servlet with URL: http://localhost:8080/MyProject/com.its.serv.MyServlet


Approach 2:
I believe when servlet is to be accessed through web.xml, it should be first "deployed" on the server or
should be kept under correct directory of already deployed web application (like DefaultWebApplication in case of Tomcat).
If your servlet is not under already deployed web application directory, you should first deploy it as war file.
Servlet from a deployed application should be accessed with following URL:
http://<server_name>:<port>/<Appli Name Given while deploying>/<servlet>

I am also new to servlet programming, so please do let me know if any of above help.
 
jQuery in Action, 2nd edition
 
subject: Not Found Error