• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Cannot invoke servlet by name!

 
Ranch Hand
Posts: 399
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, I have a problem when I want to invoke servlet by name?
I've simply mapped it in my web.xml. I can invoke it by class name or with any kind of mapping (Explicit mappings,Path prefix mappings,Extension mappings), but just to me, it won't by name. Here a simple which won't work at me:




When I call - http://localhost:8080/mywebapp/hi , I get the famous 404 Error. Does anyone know what the problem is???

[ November 19, 2008: Message edited by: Slobodan Erakovic ]
[ November 19, 2008: Message edited by: Slobodan Erakovic ]
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Your url-pattern is /hello.html but you're trying to hit it with
http://localhost:8080/mywebapp/hi

try

http://localhost:8080/mywebapp/hello.html
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Also, you should package all of your Java classes.

Your server might be able to find an un-packaged servlet but you will run into problems later (trying to locate bean classes from JSPs, for instance) if you continue using unpackaged Java classes in a web application.
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It's also a really really really bad idea to use a mapping that ends with .html.

The browsers, proxy servers, gateways and other resources on the net will assume that its a statis resource and you could run into caching issues.
 
Goran Markovic
Ranch Hand
Posts: 399
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Shouldn't I be able to invoke a servlet by registered name??? That is the question. I put my servlet in package, and I can make call to him by class name, or by (as I wrote) any sort of registered url (</url-pattern> . The reason why I put /index.html, is because of experimenting. But a problem is about invoking by registered name. I correct package name and still nothing...





Furthermore, I cannot at all invoke my servlet now (when I put it in the boby package)! The "boby" folder, with HelloWorld class is stored in "classes" folder, just as it should. But now I cannot call it neither by name, nor by class, nor by url--pattern. What is wrong now???
[ November 20, 2008: Message edited by: Slobodan Erakovic ]
 
Goran Markovic
Ranch Hand
Posts: 399
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No, really guys, I cannot inovke it at all... I registered it as :



then I try as :




without backslash, but it wont work... Neither with uri-pattern registration (either like : /hello.tml, /hello/*, or by extension!!) Nothing works!!! But, it stop working when I put it in the package so it must be a bad sort mapping....help....
 
Ranch Hand
Posts: 218
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is the problem:

<servlet-class>
boby/HelloWorld
</servlet-class>



it should be

<servlet-class>
boby.HelloWorld
</servlet-class>



assuming you class looks like this



Also as pointed out by Bear earlier change your mapping's extension from .html

make it something like this

<url-pattern>/hello.do</url-pattern>

 
Goran Markovic
Ranch Hand
Posts: 399
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes it's work now but Unfortunately you also forget to tell me :?Can I call the servlet by it's registered name, and if I can, how"???
 
Amol Nayak
Ranch Hand
Posts: 218
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Do you want to invoke it as
http://localhost:8080/mywebapp/hi ?

Simply try changing the mapping in url-pattern as

<url-pattern>
/hi
</url-pattern>

 
Goran Markovic
Ranch Hand
Posts: 399
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Aha, so I cannot perform invocation by registereg name of servlet... That's what I think so, because, despite my intention to do such a thing I couldn't. Thanks!
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There is nothing in the spec about being able to invoke a servlet by its name.

There was a period when containers had a mechanism to allow servlets to be invoked by a fully qualified class name for development and testing but, for security reasons, most containers have removed this feature.
For Tomcat this was done with the InvokerServlet.

See this to see why this is no longer active by default in Tomcat:
http://faq.javaranch.com/java/InvokerServlet

Most other containers have taken similar measures.
 
Goran Markovic
Ranch Hand
Posts: 399
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, however thanks to all for such a comprehensive discussion!

See ya around...
 
Be reasonable. You can't destroy everything. Where would you sit? How would you read a tiny ad?
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic