Inserting and displaying mathematical symbols in j2ee web application - java

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.

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

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 α<br/>
This is beta β <br/>
This is gamma Γ <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)

The following tag of struts helped me solving this to an extent.
<s:property value="name" escape="false" />

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"%>

Related

How do I get the proper characters to appear instead of "?"s in my jSP page?

I’m using JBoss 7.1.3.Final on Amazon Linux (Java 6). We have set the system property, “org.apache.catalina.connector.URI_ENCODING” to “UTF-8,” which I validate because I can call
System.err.println("encoding:" + System.getProperty("org.apache.catalina.connector.URI_ENCODING"));
and the result is
encoding:UTF-8
In our database (MySQL 5.5.37), we have a value stored,
Detectives and “Evidence”
Notice the curly quotes. This can be seen fine in our MySQL command line tool. However, on our JSP when we have
<input type="hidden" class="data-name" value=“${myMap.key.name}" />
What is output to the browser is
<input type="hidden" class="data-name" value="Detectives and ?Evidence?" />
How do we get the curly quotes to appear instead of the “?”s?
May be it's a problem connected with a characters set of a particular jsp; try to include
<%# page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
into the jsp.
Even after changing charset if issue still persist, check if you are using Stored procedure to return the value. If yes then ensure you are using 'text' data type for respective value.

need to show HTML in jsp using struts tagLib

I am working on a Java (Struts) based web application. I have to show some content by getting from DB in jsp. Example content:
<div>
some code here
<a> link here</>
</div>
I am using textarea for the time but when I put this into textarea using following tag:
<html:textarea property = "contentFromDB" rows = "12" cols = "70" styleClass = "textarea" disabled="true"/>
It shows the HTML in the textarea, is there any way I may show the content in the textarea with out HTML tags or I may show the content in any other tag like P or span, I cannot find these tags in the struts tagLib as well.
The <html:xxx> tags are for forms.
The best practice is to use JSTL's <c:out> with an appropriately-scoped object (e.g., a request attribute) and set escape to false:
<c:out value="xxx" escapeXml="false" />
Alternatively if you're on an antiquated container or just have nothing better to do, use the <bean:write> tag. I don't recall its escaping behavior(s), if any.

How to solve Flex utf-8 encoding

I develop a facebook application using flex' s XMLSocket and Java.
When i type 'ş' character in my client side, it prints, however when i send 'ş' character,
it is printed as ??? or any kind of unpredictable characters.
I tried to change my html file's meta tag to
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
but it did not work.
On the whole how can i get rid of this problem.
Thanks.
Use encodeURIComponent(yourstring), this might do the trick.

JSP exception, "quote symbol expected"

<%# page import="java.util.*" %>
<html>
<body>
<h1 align="center">blablalblalblab</h1>
<p>
<%
List styles = (List)request.getAttribute("styles");
Iterator it = styles.iterator();
while(it.hasNext()) {
out.print("<br>try: " + it.next());
}
%>
</p>
</body>
</html>
after executing my servlet request i'm getting error
org.apache.jasper.JasperException: /result.jsp (line: 1, column: 18) quote symbol expected
org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:42)
can't find any quotes that are not on right place.
Make sure all your quotes are straight quotes, not curvy ones.
Don't use Java in JSPs, please. That's what the standard tag library is for.
<%# taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<body>
<h1 align="center">blablalblalblab</h1>
<p>
<c:forEach items="${styles}" var="style">
<br>try: ${style}
</c:forEach>
</p>
</body>
</html>
In more detail:
Embedding Java code in a JSP makes the page difficult to read (JSP is a tag-oriented language), difficult to maintain, and difficult to debug.
The standard tag libraries are already debugged, have plentiful documentation and examples, and probably already Do What You Want To Do.
If you truly have some logic that needs to be performed in Java and no pre-existing tags exist, you can either a) put the logic in a bean and call it via JSTL or b) write your own tag using tagfiles.
Why is Java code better in a bean or tag library than in a JSP?
Testing is a big factor: beans and tag libraries can be tested
outside of a running servlet environment with ease.
Tag libraries are reusable and significantly cleaner than JSP includes.
I guess you have copy pasted it from somewhere, make sure the double quotes are proper. I had the same issue when I copied it from a PDF, it was resolved once I corrected my double quotes.
Your JSP works just fine with Tomcat 6. So, it's probably either some include-related issue or some previously compiled classes are not getting recompiled.
Try to clean up your Tomcat work directory and try again.
Check " if you copied it from somewhere. I had the same error because of ".
<%#taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%#page isELIgnored=”false” %>
double quotes around the false are the wrong ones. Change it to " and it will work.
While I agree with Scott A's admonition to use JSTL instead of putting Java directly into the JSP the question deserves being explored a little further. I just encountered this myself for the first time and had to dig a bit ot answer it.
Technically the error means what it says. You're missing some quotes somewhere. The simplest would be something like in your h1 tag if it read:
<h1 align=center>
instead of what you have.
<h1 align="center">
Obviously there is nothing in the code snippet that you pasted which is missing quotes so I would explore a couple of things.
First, what does the output of your it.next() look like? Since you're pulling in a list called styles I wonder if something in there is making jasper think it's a style tag instead of text you are trying to render.
Second, I would explore Pradeep's answer and see what if there is some subtle issue pasting that was resolved when you pasted it here on stackoverflow. Specifically I would look for 'smart quotes' IE many text editors (including outlook and most of office) like to use different quotes on the front and back of quoted text.
IE
'this is quoted text'
becomes
`this is quoted text'
which can be difficult to notice.

Special Characters In Webapp being saved differently

I'm creating a webapp using Spring MVC and some of the information I'm pulling is from a Database, so it was edited elsewhere. When I import some have, what I consider, special characters, such as
“_blank”
as opposed to using the standard keyboard
"_blank".
When I display this on my website textarea, it displays fine, but when I attempt to save it back into the string when submitting the form in the spring textArea, the string now has ? where the 'special' characters were. They were obviously imported into a String fine, but somewhere in the save process it's not allowing it as a special character. Any idea what is causing this or why?
Sounds like a character encoding problem. Try setting the character set of the page containing the form to UTF-8.
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />

Categories