/    Sign up×
Community /Pin to ProfileBookmark

How to get the special chars(%#&”) from JSP to Java

Hi Friends
I have a text box in my JSP. I can enter anything in the text box. And I have to retrive the value from JSP and store it in DB. I’m getting all the special characters except &%#. I tried with URL rewriting and setting into form also. Whenever I enter %#&, I’m getting empty values. How can I get these chars. Please help me.
Regards
Kasi

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@toicontienFeb 01.2008 — Are you using AJAX to post the contents of a FORM? On the JavaScript side (assuming you meant Java[B]Script[/B] when you said Java), there are two functions you'll find handy when dealing with URLs and special characters:

var name = "John Doe";
var nameEncoded = encodeURIComponent(name);

alert(nameEncoded); // Alerts "John%20Doe"


The code above takes a non URL-encoded string and encodes it so any special characters are encoded as [B]%NN[/B], where "NN" is replaced by the ASCII or UTF-8 character code. On the server side, you'll need a function in JSP that decodes the URL encoded string.

var nameEncoded = "John%20Doe";
var name = decodeURIComponent(nameEncoded);

alert(name); // Alerts "John Doe"


The code above takes a URL encoded string and decodes it. All encoded special characters are decoded to the real characters. On the server side, you'll need some function in JSP the url-encodes a string.

Can you post the HTML for your form? Also, is your form being submitting normally (by clicking a button and doing a normal form POST) or by using AJAX?
Copy linkTweet thisAlerts:
@kasipandianauthorFeb 02.2008 — Thanks for your response. I tried with encodeURIComponent() function from UI. Now I'm getting the values, What I wrote in the UI. And I dont have any function in servlet to decode the values. It's auutomatically decoding and its giving the correct value. Now my problem was solved. Thank you very much friend........

regards

kasi
Copy linkTweet thisAlerts:
@toicontienFeb 02.2008 — Glad I could help. ?
×

Success!

Help @kasipandian spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...