pri_dev
pri_dev

Reputation: 11645

backslash '\' in path is escaped

I am getting path of an xml map file like this

String path = getServletContext().getRealPath("") + "/js/"

the value when printed comes out fine as below:

C:\Users\Priyank Devurkar\Documents\NetBeansProjects\gra version1\web-app/js/

now when I pass this path to next page and alert it in the js function I get the following:

C:UsersPriyank DevurkarDocumentsNetBeansProjectsgra version1web-app/js/

I the backslashes are removed. How do I pass the path to the next page ? should I do a replace of '\' with '\'?

Upvotes: 0

Views: 5172

Answers (1)

Nic Foster
Nic Foster

Reputation: 2894

Instead of "/js/" try "\\js\\". A single backslash is an escape character, if you want to print it you need to use two of them and one of the two won't print.

This is the case for other characters often used in strings as well, like quotations, for example if you wanted to output this text: I like to use "quotes"

Your string would be: "I like to use \"quotes\""

Upvotes: 3

Related Questions