aspose file tools*
The moose likes Spring and the fly likes Spring 3 @PathVariable problem with slash Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "Spring 3 @PathVariable problem with slash" Watch "Spring 3 @PathVariable problem with slash" New topic
Author

Spring 3 @PathVariable problem with slash

Ronwaldo Cruz
Ranch Hand

Joined: Oct 17, 2006
Posts: 69
Hi,

I'm new to Spring 3. I'm trying to use @PathVariable as follows:



It works well for URLs like /test/someValueHere/test. However when someString needs to have a slash in it like /test/abc/abc/test, Spring doesn't recognize it anymore as matching the pattern. Previously I do it like /test/**/test in Spring 2.5 but this time I need to use PathVariable to easily extract out the someString value.

Anyone can help? Thanks
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17257
    
    6

Ronwaldo Cruz wrote:Hi,

I'm new to Spring 3. I'm trying to use @PathVariable as follows:



It works well for URLs like /test/someValueHere/test. However when someString needs to have a slash in it like /test/abc/abc/test, Spring doesn't recognize it anymore as matching the pattern. Previously I do it like /test/**/test in Spring 2.5 but this time I need to use PathVariable to easily extract out the someString value.

Anyone can help? Thanks


Well, to Spring those are two totally different URLs a slash has meaning in a URL. the "**" is just a wildcard the PathVariable isn't a wildcard.

Why would you want someString parameter to be "abc/abc"? Because each PathVariable usually has some kind of meaning and to me "abc" has one meaning and the other "abc" would have a different meaning.

Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
Ronwaldo Cruz
Ranch Hand

Joined: Oct 17, 2006
Posts: 69
Hi,

Ok. I understand what you mean. abc would be "sort of" a directory structure and then inside it is another abc "directory." But the thing is this is the situation I'm in. I have a url where someString in test/someString/test is a value that can have a slash in it. That is the business requirement. Is there any way of forcing the issue here and extracting someString from the path?
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17257
    
    6

Ronwaldo Cruz wrote:Hi,

Ok. I understand what you mean. abc would be "sort of" a directory structure and then inside it is another abc "directory." But the thing is this is the situation I'm in. I have a url where someString in test/someString/test is a value that can have a slash in it. That is the business requirement. Is there any way of forcing the issue here and extracting someString from the path?


The only way around it is to create two methods mapped to the two totally different URL and have one of them call the other



Now you mapped both versions and the someOtherMethod just calls someMethod so the someOtherMethod is just there to map the other URL and get that slash in there.

Hope that helps

Mark
Ronwaldo Cruz
Ranch Hand

Joined: Oct 17, 2006
Posts: 69
Thanks.
Qunfeng Wang
Ranch Hand

Joined: Jan 28, 2005
Posts: 433
I think that's not a good idea. How about the parameter has one more slash?

I have a same issue. The parameter exists in many rest API. It's annoying to add one more method seldom used to every rest API.


To be or not to be. It's a question.
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17257
    
    6

qunfeng wang wrote:I think that's not a good idea. How about the parameter has one more slash?

I have a same issue. The parameter exists in many rest API. It's annoying to add one more method seldom used to every rest API.


But in each REST api, each URL is a different resource. Nothing to do with WebPage requests. So another slash would be a different resource. So you would have that mapped to a different method. HATEOAS

Mark
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17257
    
    6

Also. Please don't resurrect old threads. This is almost a year old. The poster probably won't see your post anyway, and has already moved on long ago.

Thanks

Mark
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Spring 3 @PathVariable problem with slash