File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes Using Directory Path as Parameters? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Using Directory Path as Parameters?" Watch "Using Directory Path as Parameters?" New topic
Author

Using Directory Path as Parameters?

Rob Mech
Ranch Hand

Joined: Apr 05, 2007
Posts: 56
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?


Rob Mech, SCJP 1.5<br /><a href="http://www.robsprogrammingjunk.com/" target="_blank" rel="nofollow">http://www.robsprogrammingjunk.com/</a>
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

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

Joined: Apr 05, 2007
Posts: 56
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.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61768
    
  67

There are plenty of other methods on the request. Why not write a servlet that shows you what each returns?


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Rob Mech
Ranch Hand

Joined: Apr 05, 2007
Posts: 56
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

Joined: Mar 06, 2001
Posts: 13459

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
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61768
    
  67

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

Joined: Apr 05, 2007
Posts: 56
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.
Chris Corbyn
Ranch Hand

Joined: Jan 14, 2007
Posts: 114
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

Joined: Apr 05, 2007
Posts: 56
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
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61768
    
  67

What change is that?
Rob Mech
Ranch Hand

Joined: Apr 05, 2007
Posts: 56
Try building the servlet as I described and I'm sure you'll find out!
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61768
    
  67

I do this all the time and have never had to make any changes to the deployment descriptor.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Using Directory Path as Parameters?