• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Can not run servlet

 
Sumukh Deshpande
Ranch Hand
Posts: 87
Firefox Browser IntelliJ IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 170
Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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??
 
Sumukh Deshpande
Ranch Hand
Posts: 87
Firefox Browser IntelliJ IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Coming to your question ... can you post your web application structure and web.xml ?
 
Jonathan Elkharrat
Ranch Hand
Posts: 170
Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 87
Firefox Browser IntelliJ IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Punit Singh
Ranch Hand
Posts: 952
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Punit Singh wrote:and running servlet url-mapping is compulsory I think.


Not neccessary
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic