aspose file tools*
The moose likes Servlets and the fly likes Servlet example - error 404: how to resolve? (what is wrong?) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Servlet example - error 404: how to resolve? (what is wrong?)" Watch "Servlet example - error 404: how to resolve? (what is wrong?)" New topic
Author

Servlet example - error 404: how to resolve? (what is wrong?)

Julia Shreiber
Greenhorn

Joined: Sep 12, 2010
Posts: 28
Hi all,
I'm new here and can't find the answer.
I move my application from Tomcat 4 to Tomcat 6. My servlets work fine in Tomcat 4 and doesn't work in Tomcat 6 (of corse, I compiled it with new Java version, and most classes work fine).

The servlets make me problem structure is very similar to ChatServlet example that is configured in web.xml as following:

<servlet>
<servlet-name>ChatServlet</servlet-name>
<servlet-class>chat.ChatServlet</servlet-class>
</servlet>
.......
<servlet-mapping>
<servlet-name>ChatServlet</servlet-name>
<url-pattern>/jsp/chat/chat</url-pattern>
</servlet-mapping>

When I try to run it, it gives me 404 error:

--------------
http://localhost/examples/servlets/servlet/chat.ChatServlet

HTTP Status 404 -
type Status report
description The requested resource () is not available.
--------------

The simple examples like http://localhost/examples/servlets/servlet/HelloWorldExample etc run well.

Please help! I'm some days and can't understand what is wrong: link, configuration or my had.

Thanks in advance!




Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61238
    
  66

You set up a mapping for the servlet, and then you didn't use it. So of course it's not going to work.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Abimaran Kugathasan
Ranch Hand

Joined: Nov 04, 2009
Posts: 2066

Are you trying to access the servlet named as ChatServlet? If so, what should be your url to invoke that servlet? Check it!


|BSc in Electronic Eng| |SCJP 6.0 91%| |SCWCD 5 92%|
Ram Narayan.M
Ranch Hand

Joined: Jul 11, 2010
Posts: 247

Hit it using the URL you have set "/jsp/chat/chat"... This URL refers to the servlet with the name "ChatServlet"... Meanwhile, Please use correct names for URL Paths...Since you are using servlets, use prefix names "servlet" in url...


SCJP 6 [SCJP - Old is Gold]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61238
    
  66

Ram Narayan.M wrote:Since you are using servlets, use prefix names "servlet" in url...

No, don't. That's an old-fashioned habit left over from the days of the Invoker and is a poor practice. The URL should not specify implementation details.

On the other hand, the prefix "jsp" is just as bad, if not worse.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61238
    
  66

Ram Narayan.M wrote:Hit it using the URL you have set "/jsp/chat/chat"...

That will only work if the app is deployed as the ROOT application. In general it must be prefixed with the context path.
Julia Shreiber
Greenhorn

Joined: Sep 12, 2010
Posts: 28
Bear Bibeault wrote:You set up a mapping for the servlet, and then you didn't use it. So of course it's not going to work.


Exactly. I guess I don't know how to use it, this is the question

Ram Narayan.M wrote:Hit it using the URL you have set "/jsp/chat/chat"... This URL refers to the servlet with the name "ChatServlet"... Meanwhile, Please use correct names for URL Paths...Since you are using servlets, use prefix names "servlet" in url...


Do you mean to use link http://10.0.0.8:8080/examples/servlets/servlet/jsp/chat/chat/ChatServlet ? I tried, it gives the same result.

Bear Bibeault wrote:That will only work if the app is deployed as the ROOT application. In general it must be prefixed with the context path.


It is deployed in Tomcat\webapps\ezface-prod\WEB-INF - it is example of Apache. Other servlets deployed in the same place but more simple work fine.

I guess the problem is in using. I can't find example how to call this servlet. I tried to use it similar to simple examples like HelloWorldExample but something is wrong in my call.

http://localhost/examples/servlets/servlet/HelloWorldExample - works
http://localhost/examples/servlets/servlet/chat.ChatServlet - doesn't

How to call ChatServlet according to my config?

I understand that my question is stupid but I can't find the answer!
Michael Houlo
Ranch Hand

Joined: Jun 07, 2010
Posts: 58
i guess your url should be :
jsp/chat/chat
not
/jsp/chat/chat/ChatServlet
Julia Shreiber
Greenhorn

Joined: Sep 12, 2010
Posts: 28
Michael Leahcim wrote:i guess your url should be :
jsp/chat/chat
not
/jsp/chat/chat/ChatServlet


Thanks I tried it yesterday... and also now again...

HTTP Status 404 - /examples/servlets/servlet/jsp/chat/chat/
--------------------------------------------------------------------------------
type Status report
message /examples/servlets/servlet/jsp/chat/chat/
description The requested resource (/examples/servlets/servlet/jsp/chat/chat/) is not available.



Pravin Shirke
Ranch Hand

Joined: Apr 05, 2008
Posts: 150

Hi Julia,
you should try using what Michael has suggested.
try this



hope this helps.


[Vipassana] - It is seeing the reality as it is, And not as you want it to be.!!!
SCJP1.5.
Pravin Shirke
Ranch Hand

Joined: Apr 05, 2008
Posts: 150

Hi Julia,
you should try using what Michael has suggested.
try this



hope this helps.
Julia Shreiber
Greenhorn

Joined: Sep 12, 2010
Posts: 28
pravin shirke wrote:Hi Julia,
you should try using what Michael has suggested.
try this



hope this helps.


Thank you, great! It helps

This one worked:

http://localhost/examples/jsp/chat/chat

Thanks and thanks and thanks again!
Michael Houlo
Ranch Hand

Joined: Jun 07, 2010
Posts: 58
That's cool, you can mark it as resolved then
Julia Shreiber
Greenhorn

Joined: Sep 12, 2010
Posts: 28
Michael,
I don't see "Resolved" button here... Is it already marked?
 
Don't get me started about those stupid light bulbs.
 
subject: Servlet example - error 404: how to resolve? (what is wrong?)