| | |
Special Characters in JSP
Please support our JSP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Dec 2008
Posts: 1
Reputation:
Solved Threads: 0
Hi,
I am kind of new to JSP. I am having trouble outputing something:
<%=request.getParameter("UserName")%>
now if UserName has special Characters (i.e ♥ ) it does not get outputed corectly. that code above should display the heart symbol, but instead I get something like this: âÂ...
is there some kind of converstion function I can use?
Thanks.
I am kind of new to JSP. I am having trouble outputing something:
<%=request.getParameter("UserName")%>
now if UserName has special Characters (i.e ♥ ) it does not get outputed corectly. that code above should display the heart symbol, but instead I get something like this: âÂ...
is there some kind of converstion function I can use?
Thanks.
Last edited by sgbender; Dec 22nd, 2008 at 3:26 pm.
This isn't a JSP issue, the &heart; isn't a standard special character so you need to make sure you page will handle the it. It will be an encoding issue of some sort. Find out which character-set the heart is found in, and make the page use that set.
As sillyboy mentioned, this is not a JSP issue, the "&heart;" symbol is not supported by the Latin1 character set (ISO-8859-1) which most probably by default is the character encoding for your page.
So set change your page encoding to Unicode if you want it to be displayed.
Here is a guide on how to use special characters in HTML
So set change your page encoding to Unicode if you want it to be displayed.
Here is a guide on how to use special characters in HTML
"Any fool can write code that a computer can understand. Good programmers write code that humans can understand."
"How to ask questions the smart way ?"
"How to ask questions the smart way ?"
•
•
•
•
Hi,
I am kind of new to JSP. I am having trouble outputing something:
<%=request.getParameter("UserName")%>
now if UserName has special Characters (i.e ♥ ) it does not get outputed corectly. that code above should display the heart symbol, but instead I get something like this: âÂ...
is there some kind of converstion function I can use?
Thanks.
How exactly are you persisting the user name to your database i.e. where exactly is the user name coming from? Have you tried to print out the user name before persisting it? Is it the same as inputted by the user? Does directly writing out "♥" works?
I don't accept change; I don't deserve to live.
Problem with special characters, you have to remove special and insert ISO-8859-1 format characters
like
make a method and put all possible special character which need to replace
•
•
•
•
" = "
< = <
make a method and put all possible special character which need to replace
JSP Syntax (Toggle Plain Text)
<%! public String convSpecialChar(String htmlString) { htmlString = htmlString.replaceAll("\\<.*?\\>", ""); htmlString = htmlString.replaceAll("\r", "<br/>"); htmlString = htmlString.replaceAll("\n", "<br/>"); htmlString = htmlString.replaceAll("\"","""); htmlString = htmlString.replaceAll("\'","'"); htmlString = htmlString.replaceAll(",",","); return htmlString; } %> <%=convSpecialChar(request.getParameter("UserName"))%>
Last edited by rockonjava; Dec 24th, 2008 at 5:31 am.
![]() |
Similar Threads
- How to avoid special character error in sql query (MySQL)
- JSP database connectivity according to Model View Controller (MVC) Model 2 (JSP)
- Syntax error in INSERT INTO statement (Java)
- Not able to print XML tags in the screen ( a jsp page) (JSP)
- pass variable with space (JSP)
- Question about forms (HTML and CSS)
Other Threads in the JSP Forum
- Previous Thread: JSp Program to retrive Data from Database
- Next Thread: JSP connection to database
| Thread Tools | Search this Thread |
apache backbutton combobox connection database development directorystructure dynamicpagetitles eclipse frames glassfish ie8 imagetodatabse imageupload integer internet java javaee javascript jsf jsp jsppagetitles levels mvc2 mvcmodel2 network parameters passing ping printinserverinsteadofclient redirect request.getparameter response servlet servletdopost()readxml sessions software ssl state_saving_method stocks sun tomcat tutorial update video web






