This week's book giveaway is in the Cloud/Virtualization forum.
We're giving away four copies of Learning OpenStack Networking: Build a solid foundation in virtual networking technologies for OpenStack-based clouds and have James Denton on-line!
See this thread for details.
Win a copy of Learning OpenStack Networking: Build a solid foundation in virtual networking technologies for OpenStack-based clouds this week in the Cloud/Virtualization forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

Servlet path stupid question  RSS feed

 
Ranch Hand
Posts: 140
  • Mark post as helpful
  • send pies
  • 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
  • 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
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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
  • 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
  • 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
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • 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
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • 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
  • 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
 
Author and ninkuma
Marshal
Posts: 66801
168
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • 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 ]
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!