File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Not Found Error

 
meena latha
Ranch Hand
Posts: 219
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 167
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
satishkumar janakiraman
Ranch Hand
Posts: 334
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64185
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Why in the name of heaven would you override these methods to return null?
[ July 29, 2005: Message edited by: Bear Bibeault ]
 
meena latha
Ranch Hand
Posts: 219
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64185
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 219
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64185
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13411
Firefox Browser Redhat VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
meena latha
Ranch Hand
Posts: 219
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 27
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic