Win a copy of Microservices Testing (Live Project) this week in the Spring forum!
  • 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:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Liutauras Vilda
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Mikalai Zaikin
  • Himai Minh

apostripy problem

 
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Iam passing the name from one jsp to another jsp by using javascript function.

suppose the name contains like this o'really then it gives java script errors while passing the name.

I think javascript doesnot accepting special chars. So could you please help me regarding this issue ASAP.

I dont want to remove the special char, i want to allow the char because we need to display the name on header as it is what they are entered.

Regards
deva
 
Ranch Hand
Posts: 367
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi!

You must replace ' char with \'

Use regExp. The string.replace() function only takes the first '

// Mathias
[ November 24, 2005: Message edited by: P.W Mathias Nilsson ]
 
Sheriff
Posts: 67650
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
For future reference: apostrophe
 
deva siva
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi

i dont want to replace that char (- ' ), i want to allow this chars, into javascript functions because i need to display the user name on the header as it is.

And one more thing, the name some times contains hiphen and apostrophe also,

could you please help me

regards
devasiva
 
Sheriff
Posts: 6959
2
Eclipse IDE Debian Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by deva siva:
i dont want to replace that char (- ' ), i want to allow this chars, into javascript functions because i need to display the user name on the header as it is.



Which is exactly what "escaping" the character (by preceding it with a "backslash" [\] ) does.

Any time you put a character in a constant text string you need to "escape" characters that might confuse the programming language. The way languages such as Java, C, C++, C# and Javascript do this is by using '\' as an "escape character" to tell the language parser to leave the next character alone.

However; I notice from your initial question that you are passing information from one JSP to another. In this case you also need to be careful when building URLs. If you are using a GET request with parameters on the end of the URL you really need to "URL encode" any dangerous or unusual characters. There's plenty of information on tghe web about this, for example http://sislands.com/coin70/week6/encoder.htm
reply
    Bookmark Topic Watch Topic
  • New Topic