-1

I have mathematical symbols e.g. alfa, beta,mu . When I copy these symbols in text area they are getting copied. I am copying them from word document. When I insert them into the database using prepared statement the symbols are getting inserted as code. for example the alfa is getting stored as β. This is fine I guess. But when I retrieve them from the database using java.sq.Statement and displaying them in the html page they are getting displayed as code instead of symbol. I mean "β" is displayed in html instead displaying alfa symbol. So how to deal with this situation? how can I store symbols and display them properly in html?

I am using mysql database, java1.7,struts2.0 and tomcat7.

4 Answers4

1

The correct display of HTML characters is: β (Looks like: β) You need to add a semicolon.

schnawel007
  • 3,982
  • 3
  • 19
  • 27
0

1) How are you displaying the codes in HTML?

2) What is the char encoding of machine your are running your server/viewing your html

I had following code and it worked

<html> <body> This is alpha &#945;<br/> This is beta &#946; <br/> This is gamma &#915; <br/> <body> </html> as shown below:

This is alpha α
This is beta β
This is gamma Γ

You may need to declare your charset:

<meta http-equiv="content-type" content="text/html;charset=utf-8" />

or see the encoding of your server (if its in jsp)

Optional
  • 4,387
  • 4
  • 27
  • 45
  • yes it is a jsp. but i have added tag as shown by you in the adding page and display page but the code is getting displayed as &#946; so how can i deal with this. i see the value of the Alfa symbol in the database it is correct only. it is β. but when i retrieve them through java.sql.statement interface and displaying in the jsp page it is getting displayed as &#946; so how can i deal with this? – Muralidhar Yaragalla Jul 30 '15 at 07:37
  • @MuralidharYaragalla Can you share your jsp code how you are showing the date. It may be converting & to & Try like: <% request.setAttribute("specialCharString", "β"); %> HTML: ${specialCharString} And see what it prints. – Optional Jul 30 '15 at 07:48
  • @MuralidharYaragalla So now you got the idea how u can display your characters from DB. Get it in some string and display it. If required, you may need to unescape string – Optional Jul 30 '15 at 08:21
0

The following tag of struts helped me solving this to an extent.

<s:property value="name" escape="false" />
0

I hope you're using JSPs. Add this import on top of your JSP which is rendering the symbols:

<%@ page contentType="text/html;charset=UTF-8" pageEncoding="UTF-8"%>
f_puras
  • 2,521
  • 4
  • 33
  • 38
sw-enthusiast
  • 199
  • 1
  • 2
  • 17