Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Handling Special Characters in Url in Struts2

 
SriLakshmi Balusu
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have an URL constructed in my mapper something as follows

"&feeOrRebate=" + getFeeOrRebate() +
"&securityName=" + getSecurityName();

This is sent to JavaScript where an Ajax call is made and appropriate action is invoked from which a pop-up would be displayed. In the pop-up we are displaying certain fields that are sent from above url.

Now the problem is if my SecurityName is 'A & B Corporation', in the pop-up it's displayed as just 'A' all the string after '&' is chipped off.

Could some one tell how this string should be handled before making an Ajax call...
String can have any special character like '&', '@', ':', '%', '-', '_','.' etc.,

Thanks in adavance.

SriLakshmi
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You should URL escape it.
 
SriLakshmi Balusu
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes I tried using URLEncoder.encode( getSecurityName(), "UTF-8"); in my mapper and later decoded it in my Action class. But it din't work..

Thanks,
Sri~
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65227
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please be sure to ask Struts questions in the Struts forum. I have moved this post there for you.
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please see ItDoesntWorkIsUseless.

Escaping parameters *does* work, people do it all the time.
 
Tejas Aryan
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
UTF-8 is primarily meant for globalization. To make your jsp page render non-English characters. It doesn't work well for special characters like #,@ etc. The only way , as far as I know, is to encode at origin and decode where it is received. I have posted a similar question in Servlets forum.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic