• 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

Servlet path stupid question

 
Ranch Hand
Posts: 140
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

My stupid question is:

I always see my url to a servlet like:

http://localhost/servlet/test

Is it possible to have my url something like this:

http://localhost/test

or

http://localhost/<something>/test

Is there any simple way to do this like in web.xml? Besides that I would still want my http://localhost/servlet/test to be valid.

Thanks.

Regards,
Vikas
 
Ranch Hand
Posts: 116
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hello vikas,

The only stupid question is the one that is never asked. Its a very good question and I don't know the answer myself correctly.

I may be wrong but this is what I think of this situation,
if you are mapping "/test/*" this would mean any url which has /test/ context. So it maps both "/servlet/test/" and "/test" to this mapping.

We shall wait for any expert to answer this corretly though.
 
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It's all in your web.xml servlet-mapping tag.



Now, your servlet should be available under all three requests.
 
vishwanath nadimpally
Ranch Hand
Posts: 116
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Gregg Bolinger:
It's all in your web.xml servlet-mapping tag.



Now, your servlet should be available under all three requests.



I knew I was wrong. Thanks for the correct answer.
 
Vikas Aggarwal
Ranch Hand
Posts: 140
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the answer. Now I have got a problem with this solution.

I have around 536 servlets in my app and it is impossible or rather time consuming and error prone to list all of them in web.xml. Is there a way to make this work for all servlets.

Thanks.
Vikas
 
vishwanath nadimpally
Ranch Hand
Posts: 116
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
536 servlets , yeah good luck with that buddy
 
Vikas Aggarwal
Ranch Hand
Posts: 140
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes it is an old app with no luck at all. So is it possible to do something about it?
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes and no. Don't you love that answer? You need to consider using the Front Conroller pattern. Basically, you need a single servlet that is mapped in your web.xml and that servlet will parse the request and foward the process to a particular "action" that handles the request. This is basically what frameworks like Struts do. There is tons of discussion on Front Controller including this nifty little article written by our very own Bear.

http://www.javaranch.com/journal/200603/Journal200603.jsp#a5
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Vikas Aggarwal:
Yes it is an old app with no luck at all. So is it possible to do something about it?



If you are dealing the legacy code and you can't utalize a Front Controller, then you are out of luck. You have to specify those mappings to get the desired results.
 
Vikas Aggarwal
Ranch Hand
Posts: 140
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
To be honest, I completely loved your answer. Front controller is a good idea. I will see its feasibility in my project.

Thanks a lot for your help.

Vikas
 
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
Thanks for the plug Gregg!

Yes, the very problem of "deployment descriptor bloat" is discussed in that article.

A Front Controller can be very simple and light-weight -- you don't need a behemoth like Struts just to implement one.

The article touches the high level design of such a controller but doesn't go into great detail. My next planned article will be on the detailed design of a Front Controller but you probably can't wait around for that.
[ October 11, 2006: Message edited by: Bear Bibeault ]
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic