aspose file tools
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes Can not run servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Reply Bookmark "Can not run servlet" Watch "Can not run servlet" New topic
Author

Can not run servlet

Sumukh Deshpande
Ranch Hand

Joined: Feb 17, 2008
Posts: 87

I am trying to run HelloWorldServlet from SCWCD EXAM STUDY KIT SECOND EDITION book by Hanumant Deshmukh .
Page number : 8 to 10.
When I try to run the servlet as: http://localhost/chapter01/servlet/HelloWorldServlet I get 404 error.
But when I do url-mapping it works fine.

Is it that Tomcat Version 4.4 onwards url-mapping is compulsory? .I am using tomcat 5.5.

Please help.
Thanks in advance.
Jonathan Elkharrat
Ranch Hand

Joined: Dec 31, 2008
Posts: 170

did you compile the file?
and put it in the "webapps\chapter01\WEB-INF\classes" directory?
and put the web.xml in "webapps\chapter01\WEB-INF"?
this exmples use something that i vaguely remember as "invoker"
but it's not recommended.

it's better to use a url mapping:
<servlet-mapping>
<servlet-name>HelloWorldServlet</servlet-name>
<url-pattern>/servlet/HelloWorldServlet</url-pattern>
</servlet-mapping>

and also check that tomcat is really on localhost. isn't tomcat on localhost:8080 by default??

SCJP 5, SCWCD 5, SCBCD 5
Sumukh Deshpande
Ranch Hand

Joined: Feb 17, 2008
Posts: 87

Yes Jonathan Elkharrat I have done all those things which you are specifying.
But still it does not work!

I also know that not specifying url mapping is not a good practice.

But can you still answer my question Is it that Tomcat Version 4.4 onwards url-mapping is compulsory?
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

Sumukh Deshpande wrote:
But can you still answer my question [i][b]Is it that Tomcat Version 4.4 onwards url-mapping is compulsory?

No. but if you want to start the servlet by url-pattern then you need to specify. other wise to start the servlet you need <load-on-startup>
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

Coming to your question ... can you post your web application structure and web.xml ?
Jonathan Elkharrat
Ranch Hand

Joined: Dec 31, 2008
Posts: 170

you must use a servlet-mapping (url-mapping doesn't exist..)

there's a feature in tomcat that you can call any servlet by it's
name using the prefix "/servlet/*".
(check the conf/web.xml for details)
this let you call the servlet just with the name you put after "/servlet/*".
i think it's disactivated by default (again, check your conf/web.xml to
see if it's disabled or not) and i recommend you not to use this feature.

just use the <servlet-mapping> element and you should be fine...
Sumukh Deshpande
Ranch Hand

Joined: Feb 17, 2008
Posts: 87

If anybody has the book I specified initially please have a look into page numbers I noted.

The book does not say anythig about url-mapping for that particular example.

I have followed the same structure as specified in book.
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14685
    
  16

The book does not say anythig about url-mapping for that particular example.

Then the book is probably using the InvokerServlet. Read the FAQ and try to enable it.


[My Blog]
All roads lead to JavaRanch
Punit Singh
Ranch Hand

Joined: Oct 16, 2008
Posts: 952
Sumukh Deshpande wrote:I am trying to run HelloWorldServlet from SCWCD EXAM STUDY KIT SECOND EDITION book by Hanumant Deshmukh .
Page number : 8 to 10.
When I try to run the servlet as: http://localhost/chapter01/servlet/HelloWorldServlet I get 404 error.
But when I do url-mapping it works fine.

Is it that Tomcat Version 4.4 onwards url-mapping is compulsory? .I am using tomcat 5.5.

Please help.
Thanks in advance.


He has already written, with url-mappint it works fine, and running servlet url-mapping is compulsory I think.


SCJP 6
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

Punit Singh wrote:and running servlet url-mapping is compulsory I think.


Not neccessary
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: Can not run servlet
 
Similar Threads
deployement of a simple servlet
Problem running servlet in tomcat
problem running the HelloWorld ! servlet
HttpStatsuError
Example Context doesnot respond (Jboss With tomcat)