• 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:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

Using Directory Path as Parameters?

 
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'd like to pull of a directory path to use that for parameters. Let me give an example


Servlet named "NewsInfo"

www.mysite.com/NewsInfo/Local/60146/

Basically I want to pull off the "Local" as a parameter and "60146" as a parameter. I don't want this to be a traditional parameter since many search engines rip off everything after the ? on a spider.

Any way to do this with a servlet or other J2EE technology?
 
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yep, check the API for the other information available from the request, it's all there
(I'd give you the answer, but it isn't difficult and I think the time spent wandering the API is valuable )
 
Rob Mech
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by David O'Meara:
Yep, check the API for the other information available from the request, it's all there
(I'd give you the answer, but it isn't difficult and I think the time spent wandering the API is valuable )



Well I've done that already hense my post. I thought it had something to do with getContextPath but I wasnt sure how to apply that to the servlet itself. Hense my post.

Are you suggesting that getContextPath for the above URL would return everything after the servlet name? If so that's hardly clear from the API documentation for getContextPath.
 
Sheriff
Posts: 67754
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
There are plenty of other methods on the request. Why not write a servlet that shows you what each returns?
 
Rob Mech
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Bear Bibeault:
There are plenty of other methods on the request. Why not write a servlet that shows you what each returns?



Yeah, guess I could do that but then why did I bother posting a question on the friendly site for greenhorns. Seems pointless to ask a question to be told find it yourself.
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You're going to make me admit that I can't remember, aren't you?

I worked out how to do using Bear's method, you should give it a go
 
Bear Bibeault
Sheriff
Posts: 67754
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

Originally posted by Rob Mech:
Yeah, guess I could do that but then why did I bother posting a question on the friendly site for greenhorns. Seems pointless to ask a question to be told find it yourself.



There is nothing unfriendly about teaching a man how to fish. JavaRanch is primarily a learing site -- not someplace to just get an answer without understanding. You will much more often be led down a path of discovery rather than given a code snippet.

There's a big difference between "do it yourself" and "here's a clue to help you find out the answer to this, as well as similar questions in the future".
 
Rob Mech
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Bear Bibeault:


There is nothing unfriendly about teaching a man how to fish. JavaRanch is primarily a learing site -- not someplace to just get an answer without understanding. You will much more often be led down a path of discovery rather than given a code snippet.

There's a big difference between "do it yourself" and "here's a clue to help you find out the answer to this, as well as similar questions in the future".



Agreed, but you dont show a person an ocean and say there it is either. I'd of been fine with the method of the api without the code snippet. Either way I'll find what I need elsewhere.
 
Ranch Hand
Posts: 114
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is fairly trivial really but I'm working on the same thing on and off so I'd be happy to post (GPL) code once it's done. If you want completely flexible (not set suffix or prefix) URLs then you end up having to do some jiggery-pokery with filters but it works.

To give you an idea on the interface:

XML configuration:


Factory class:


The factory just reads the XML and builds a "Router" object with a list of "Rules". You need to wrap the request object in order for it to work to because the Map used by ServletRequest is immutable.
[ August 24, 2007: Message edited by: Chris Corbyn ]
 
Rob Mech
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I was eventually able to get it to work. While the servlet api did have the method listed in it there was a change to web.xml that also had to be made.

[Edit: not-so-nice comment removed. Even if you do not agree with the approach being taken to try and help you answer your questions, please try to keep your tone civil.]
[ August 24, 2007: Message edited by: Bear Bibeault ]
 
Bear Bibeault
Sheriff
Posts: 67754
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
What change is that?
 
Rob Mech
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Try building the servlet as I described and I'm sure you'll find out!
 
Bear Bibeault
Sheriff
Posts: 67754
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
I do this all the time and have never had to make any changes to the deployment descriptor.
 
reply
    Bookmark Topic Watch Topic
  • New Topic