Pradeep Rama
Pradeep Rama

Reputation: 1

How to have "/" forward slash in @RequestMapping?

I have a requirement where the id I use in @RequestMapping accept a value of the format 1234567812345678 and abcxyz/abcxy+z$ (basically a auto generated string with / forward slash in it).

I have tried a mapping of all the 3 below formats but nothing works:

@RequestMapping(value="abc/action/{id: .+[//]*.*}.{format}", method=RequestMethod.PUT) -- Accepts nothing.

@RequestMapping(value=" abc/action/{id:.+}.{format}", method=RequestMethod.PUT) -- Accepts everything except /

@RequestMapping(value=" abc/action/{id:.*}.{format}", method=RequestMethod.PUT) -- Accepts everything except /

However, when I try the same regex in a normal java program, it works like a charm :

package miscellenousTest;
public class RegExTest {
    public static void main(String[] args) {
        String s1 ="9876543298765432";
        String s2 =" abcxyz/abcxy+z$";
        System.out.println(s1.matches(".+[//]*.*"));
        System.out.println(s2.matches(".+[//]*.*"));
    }
}

I have gone through some of the previous posts but nothing gives me the exact solution I am looking for.

It will be great if someone can throw some pointers/solution at this one.

Upvotes: 0

Views: 2057

Answers (1)

Bruce Lowe
Bruce Lowe

Reputation: 6213

you should not use slashes when sending data in urls. You will need to urlencode it before sending it. It will then be decoded before being given back to you.

Sometimes I make web safe names when i come across this problem. So for example i need to sometimes send ids like "12345/01". When I send them over the web in urls, I say "12345_01", which we refer to as the web safe id. we then convert it by replacing _ with / when we need the real id.

Upvotes: 1

Related Questions