aspose file tools*
The moose likes Struts and the fly likes Handling Special Characters in Url in Struts2 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of JavaScript Promises Essentials this week in the JavaScript forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Handling Special Characters in Url in Struts2" Watch "Handling Special Characters in Url in Struts2" New topic
Author

Handling Special Characters in Url in Struts2

SriLakshmi Balusu
Greenhorn

Joined: Oct 05, 2009
Posts: 2
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

Joined: Sep 29, 2008
Posts: 12617

You should URL escape it.
SriLakshmi Balusu
Greenhorn

Joined: Oct 05, 2009
Posts: 2
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

Joined: Jan 10, 2002
Posts: 61594
    
  67

Please be sure to ask Struts questions in the Struts forum. I have moved this post there for you.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Please see ItDoesntWorkIsUseless.

Escaping parameters *does* work, people do it all the time.
Tejas Aryan
Greenhorn

Joined: Apr 12, 2009
Posts: 22
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Handling Special Characters in Url in Struts2