I have J2EE web application that is deployed on tomcat on windows and ubuntu.
There is a text "Raphaël", that I am reading from local file(csv) system, that is coming correctly on ubuntu browsers, but it is coming as "Raphaël" on windows browsers.
I am using in Jsp
<meta charset="utf-8">
Also I have tried following meta tags also, but they didn't work.
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
What could be the problem here?
CSV reading code is
reader = new CSVReader(new FileReader(file));
final List<String[]> licenses = reader.readAll();
Check that you have UTF-8 encoding in both CSV file and JVM.
For JVM setting use :
-Dfile.encoding=UTF8
To check file encoding on linux use:
file --mime-encoding file.name
For setting encoding on JSP page use:
<%# page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
If that does not help add a filter in order to have proper encoding for all responses:
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
throws ServletException
{
request.setCharacterEncoding("UTF-8");
chain.doFilter(request, response);
}
Set your JSP contentType as UTF-8
<%# page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
First you need to read the file using correct encoding. The way you read the file depends on the default encoding of J2EE server's JVM, which can be anything. My suggestion is to do something like this:
final FileInputStream instream = new FileInputStream(file);
CSVReader reader = new CSVReader(new InputStreamReader(input, "UTF-8"));
and also set UTF-8 encoding in the JSP as Joseph has written above:
<%# page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
Related
I am getting "The character encoding of the plain text document was not declared. The document will render with garbled text in some browser configurations if the document contains characters from outside the US-ASCII range. The character encoding of the file needs to be declared in the transfer protocol or file needs to use a byte order mark as an encoding signature" on hitting my REST endpoint
my jsp header
<%# page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8"
</head>
my endpoint
#Path("/create")
#POST
#Consumes(MediaType.APPLICATION_FORM_URLENCODED)
As mentioned by #lucumt you have a syntax error in your code. the meta tag is not ending correctly in /> - also I corrected the lower case of utf-8 to uppercase:
<%# page contentType="text/html; charset=UTF-8" language="java" %>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
</head>
I am trying to integrate Simplify Commerce payment system into my project
but I can't seem to get it right.
This is one of the problems:
<%# page import="com.simplify.package"%>
and I got this error after mousing over the red wavy line:
Syntax error on token "package", * expected
I then added a `*` like this `com.simplify.package.*`
And I got this:
`Syntax error on token "package", Identifier expected`
I already added all the .jar files to the `WEB-INF/lib` folder.
What seems to be the problem?
The jsp that I am trying to import the jar file:
<%# page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%# page import="com.simplify.package.*" %>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Pay Now!</title>
</head>
<body>
<%
PaymentsApi.PUBLIC_KEY = "";
PaymentsApi.PRIVATE_KEY = "";
CardToken cardToken = CardToken.create(new PaymentsMap()
.set("card.addressCity", "OFallon")
.set("card.addressState", "MO")
.set("card.cvc", "123")
.set("card.expMonth", 11)
.set("card.expYear", 19)
.set("card.number", "5105105105105100")
);
System.out.println(cardToken);
%>
There are red way lines under PaymentsApi and CardToken
Unpacking the jar file to look at the package structure solved it.
I am trying to integrate my report in JSP page. Report created using jaspersoft studio. But i am getting null pointer exception on runReportToPdf line. I am totally new to this report and web application. So please someone help to resolve this and get excepted result. Quick support will be very much appreciated. Thanks.
<%# page import="java.io.*"%>
<%# page import="java.sql.Connection"%>
<%# page import="java.sql.DriverManager"%>
<%# page import="java.util.HashMap"%>
<%# page import="java.util.Map"%>
<%# page import="net.sf.jasperreports.engine.*"%>
<%# page trimDirectiveWhitespaces="true" %>
<%# page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<h2>Report!</h2>
<%
Connection con = null;
try{
Class.forName("oracle.jdbc.driver.OracleDriver");
con=DriverManager.getConnection("jdbc:oracle:thin:#192.168.0.248:1521:incomingqc", "inqc", "megaWIN123$");
System.out.println("i AM IN CONNECTION");
}catch (Exception ex) {
System.out.println("i AM ex para");
ex.printStackTrace();
}
File reportFile = new File(application.getRealPath("Blank_A4_Landscape.jasper"));//your report_name.jasper file
Map parameters = new HashMap();
byte[] bytes = JasperRunManager.runReportToPdf(reportFile.getPath(), parameters, con);
response.setContentType("application/pdf");
response.setContentLength(bytes.length);
ServletOutputStream outStream = response.getOutputStream();
outStream.write(bytes, 0, bytes.length);
outStream.flush();
outStream.close();
%>
</body>
</html>
PDF and HTML content cannot be mixed. When the JSF page generates the HTML, it writes to a temporary buffer. That temporary buffer is sent to the browser once JSF is told that the response is complete.
In the given code, here is a rough idea of what the web browser will receive:
<html><head></head><body><h2>Report!</h2>%PDFNΘs*̶͑̾̾̅ͫ͏̙̤g͇̫͛͆̾ͫ̑͆l͖͉̗̩̳̟̍ͫͥͨe̠̅s...</body></html>
For the browser to display the report there are a few options:
Generate an HTML version of the report and use <h:outputFormat> to inject the report content into the existing web page.
Generate a PDF version of the report and use <h:commandLink> or <h:commandButton> with an action that writes the PDF to the browser, much as you've already done.
Mixing both approaches as shown in the question, however, will not produce the desired result.
See also:
How to provide a file download from a JSF backing bean?
Send a PDF to browser via JSF
http://www.jroller.com/hakan/entry/jasperreports_and_jsf_integration
downloading data using Active query from JSP page with some parameters is leading to character problems. Special characters in the german language as for example, ö, ä, ß are printed as ö, ä and ß.
Debugging the JSP page in Java shows that the result that is returned by the JSP page is correct. So the problem seems to be due to conversion within excel after download, most probably due to a unsopported charset.
I tried to convert the result string in JSP to different charsets, but the problem still persists.
Does anyone know a solution?
Thank You very much in advance!
Did you try setting the encoding of the page?
<%# page contentType="text/html; charset=UTF-8" pageEncoding="UTF8" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
...
If you can't find a solution on the Microsoft side, I'd recommend this alternative here:
http://poi.apache.org/
How to check what really charset, encoding of some html page ?
For example, the charset of some html page is iso-8859-1, but the content of the html written with utf8
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
...
here is content with utf8
...
</html>
How to check it, Is it possible to check with java charset, encoding of html page,
like it's done in browsers ?
Thank you !