Special characters like ä, ö, ü - google-app-engine

I’m trying to get special characters like the German Umlaut (ä, ö, ü) working with the Google App Engine, but sadly it dosen't work. The Eclipse text file encoding is set to UTF-8, I use <meta http-equiv="content-type" content="text/html; charset=UTF-8"> in my index.html and the web.xml is also using encoding="utf-8".
If I compile my project locally, the characters are shown correctly. If I deploy it to the google appspot the characters are shown like this: ��. I checked also the Browser encoding, this is set to UTF-8, what did I miss?
Edit
Here is a example which works locally but not online:
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<title>ä ö ü</title>
</head>
<body>
<form name="profile" action="">
<select name="p" size="1">
<option value="1">ä</option>
<option value="2">ö</option>
</select>
</form>
</body>
Edit2
I could isolate the problem. At the start I use the google channel api to communicate with the clients. Here I write the token to the users. This is the problem. Here is the code:
I guess I have to convert to UTF-8, but where?
FileReader reader = new FileReader("index.html");
CharBuffer buffer = CharBuffer.allocate(16384);
reader.read(buffer);
reader.close();
String index = new String(buffer.array());
index = index.replaceAll("\\{\\{ token \\}\\}", token);
index = index.replaceAll("\\{\\{ user \\}\\}", account);
resp.getWriter().write(index);
Why the characters are not shown correctly online?

FileReader always uses the platform default encoding. Use
InputStreamReader(new FileInputStream("index.html"), "UTF-8")

Related

Removing .html from end of url in javalin

I'm using Javalin to serve my static web pages, which I've never done before. I know it's possible in Nginx to remove the .html from the end of your url but still route to the correct page, for example mysite.com/login would replace mysite.com/login.html but still point towards my login.html file. Is this possible in Javalin?
I've tried looking into the config (StaticFileConfig) but couldn't seem to find anything that would solve this problem
Here are two examples of what was discussed in the comments to the question, for future visitors:
The first example assumes there is a simple HTML file in the application's resources/html folder.
The test.html file:
<!DOCTYPE html>
<html>
<head>
<title>Test</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<div>Hello world.</div>
</body>
</html>
The /test handler:
public static void main(String[] args) {
Javalin.create(config -> {
})
.get("/test", ctx -> {
ctx.contentType(ContentType.TEXT_HTML);
InputStream in = App.class.getResourceAsStream("/html/test.html");
ctx.result(in);
})
.start(8080);
}
If you choose to configure Javalin with Thymeleaf, and if you place your HTML file in the default location expected by Thymeleaf (resources/thymeleaf), then you can do this:
.get("/test", ctx -> {
Map<String, Object> model = new HashMap<>();
ctx.render("test.html", model);
})
In this case, the model used by Thymeleaf for rendering is empty because you don't need to make any substitutions in your HTML file (it's not a template). But it's a short step from this to using dynamic Thymeleaf templates.
I followed what andrewJames was saying and that worked for me. I was hoping there would be a cleaner way of doing this, as I'm just copy pasting the same code for every endpoint and changing the file path, but this works.

Data file location relative to html when running Azure Maps tutorials locally - atlas.io.read()

Trying to determine how to revise the atlas.ioread() function from the Azure Maps tutorial below to read the data locally on my windows machine.
atlas.io.read(window.location.origin + '/Common/data/Gpx/Route66Attractions.xml')
Does the 'window.location.origins +' work with local files?
I have nested the .xml file similarly to the above string, relative to the html file, however, it does reading the file when the map is launched.
Azure Maps Tutorial:
https://github.com/Azure-Samples/AzureMapsCodeSamples/blob/master/AzureMapsCodeSamples/Spatial%20IO%20Module/Load%20spatial%20data%20(simple).html
That function won't be able to access local files directly as the URL must be a http or https URL. There are a couple of approaches you can take.
If you plan to host the file later, you can host it locally on localhost and then have a URL pointing to it.
If you want to access local files, you will first need to load the file into your app using the file input tag and the FileReader class. Once you have the raw file data (text), you can pass that into the atlas.io.read function and it will process if for you. Here is a simple example:
<!DOCTYPE html>
<html>
<head>
<title>Read Text File</title>
<!-- Add references to the Azure Maps Map control JavaScript and CSS files. -->
<link rel="stylesheet" href="https://atlas.microsoft.com/sdk/javascript/mapcontrol/2/atlas.min.css" type="text/css" />
<script src="https://atlas.microsoft.com/sdk/javascript/mapcontrol/2/atlas.min.js"></script>
<!-- Add reference to the Azure Maps Spatial IO module. -->
<script src="https://atlas.microsoft.com/sdk/javascript/spatial/0/atlas-spatial.min.js"></script>
</head>
<body>
<input type="file" name="inputfile" id="inputfile">
<script type="text/javascript">
window.onload = function() {
var input = document.getElementById('inputfile');
input.addEventListener('change', function() {
var fr = new FileReader();
fr.onload = function(){
atlas.io.read(fr.result).then(function(r){
//r is the parsed data. Do something with it.
});
}
fr.readAsText(input.files[0]);
});
});
</script>
</body>
</html>

Chinese filename getting garbled once saved to server

I have a Classic ASP page with an <input type="file"/> control. When a file with Chinese filename is being uploaded to the server, it gets garbled into some weird characters.
Original FileName: 你好,你能听到我.jpg
Filename in server: 你好,你能å¬åˆ°æˆ‘.jpg
Is there a way in which we can restrict this? My requirement is to let the user download the uploaded file later, and the original filename must stay intact.
I have added this in web.config:
<globalization requestEncoding="utf-8" responseEncoding="utf-8" fileEncoding="utf-8"/>
All my pages have:
<% codepage="65001" %>
<% Response.charset ="utf-8" %>
<% If Form.State = 0 Then
Form.CharSet = Response.CharSet%>
<html>
<head>
<title>Document Upload Wizard</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
I have a first page FileUpload1.asp which has the <input type="file"> and then a Submit button which navigates to FileUpload2.asp where this is how the upload is happening:
Set Directory = Server.CreateObject("ActiveFile.Directory")
Set Post = Server.CreateObject("ActiveFile.Post")
Set Post.Directory = Directory
Directory.Path = "D:\ApplicationDocuments\TEMPFOLDER\Product_Live\"
Post.Upload Directory.Path
In the server I get the filename garbled.

wpf webBrowser NavigateToString script error

I want to use the Wpf webBrowser control to render math equations.
I've downloaded MathJax, and included it in my Visual studio project.
I've tryed to load one of the MathJax example. This is the html code i'm using:
<!DOCTYPE html>
<html>
<head>
<title>MathJax MathML Test Page</title>
<!-- Copyright (c) 2010-2012 Design Science, Inc. -->
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<script type="text/javascript" src="MathJax-Reduced/unpacked/MathJax.js?config=TeX-AMS-MML_HTMLorMML-full"></script>
</head>
<body>
<p>
When
<math xmlns="http://www.w3.org/1998/Math/MathML">
<mi>a</mi><mo>≠</mo><mn>0</mn>
</math>,
there are two solutions to
<math xmlns="http://www.w3.org/1998/Math/MathML">
<mi>a</mi><msup><mi>x</mi><mn>2</mn></msup>
<mo>+</mo> <mi>b</mi><mi>x</mi>
<mo>+</mo> <mi>c</mi> <mo>=</mo> <mn>0</mn>
</math>
and they are
<math xmlns="http://www.w3.org/1998/Math/MathML" display="block">
<mi>x</mi> <mo>=</mo>
<mrow>
<mfrac>
<mrow>
<mo>−</mo>
<mi>b</mi>
<mo>±</mo>
<msqrt>
<msup><mi>b</mi><mn>2</mn></msup>
<mo>−</mo>
<mn>4</mn><mi>a</mi><mi>c</mi>
</msqrt>
</mrow>
<mrow> <mn>2</mn><mi>a</mi> </mrow>
</mfrac>
</mrow>
</math>
</p>
</body>
</html>
Everything is working fine with the following code:
string curDir = Directory.GetCurrentDirectory();
this.webBrowser1.Navigate(new Uri(String.Format("file:///{0}/test-1.html", curDir)));
But if i try this code:
string s = File.ReadAllText(Directory.GetCurrentDirectory() + "\\test-1.html");
this.webBrowser1.NavigateToString(s);
i get a Script Error:
An error has occurred in the script on this page.
Line: 1
Char: 1
Error: Syntax Error
Code: 0
URL: about:MathJax-Reduced/unpacked/MathJax.js?config=TeX-AMS-MML_HTMLorMML-full
What's wrong? It would be really helpful to use something similar to the last code, so i can avoid to save a file just to load it...
Note that the URL in the error is about:MathJax-Reduced/unpacked..., which is an about URL not the file:// URL that you had in the first case. I suspect that is the cause of the problem. That suggests that the NavigateToString function is using about:blank or a similar URL as the base URL for the page, so MathJax is getting the wrong path to itself. Note that you lose the actual page location when reading it from the file and loading it as a string. That means you may have to load MathJax from an absolute URL rather than a relative one (i.e., include the file:// and path to the MathJax-Reduced directory).

Declaring mime type for html-email

I want to create a html email and I've read a lot about how to do it. There is one piece of information I can't find. How should I declare the mime type? I tried with:
meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
but it doesn't work.
Later edit:
I am trying to set the content-type of the mail to text/html but I don't know how. All this when writing from a regular email client. I have to declare it in the mail body? Or in the mail header (if so, how do I o it?)?
Are you trying to set the content-type declaration within the message header sent to the mail server? If so, you should set it this way, in a line itself:
Content-Type: text/html; charset=UTF-8
The end tag for meta tag is used only in xhtml/xml. If you are using html, you should use it inside <head> tags like:
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
Basically email clients ignore any META tags with Content type in them (at least as of 2013-10-17).
You need to set a the content type declaration in a special header in the email server.
More information about this issue can be found at http://www.emailonacid.com/blog/details/C13/the_importance_of_content-type_character_encoding_in_html_emails
If this makes no sense to you, then I'm afraid you're out of luck. The only reliable solution I've found is to convert any special characters to their HTML entity equivalent. The link above has a link to a tool that does this for you.
Hope that helps!
This applies to php:
// To send HTML mail, the Content-type header must be set
$headers[] = 'MIME-Version: 1.0';
$headers[] = 'Content-type: text/html; charset=iso-8859-1';
// Additional headers
$headers[] = 'To: Mary <mary#example.com>, Kelly <kelly#example.com>';
$headers[] = 'From: Birthday Reminder <birthday#example.com>';
$headers[] = 'Cc: birthdayarchive#example.com';
$headers[] = 'Bcc: birthdaycheck#example.com';
// Mail it
mail($to, $subject, $message, implode("\r\n", $headers));
http://php.net/manual/en/function.mail.php#example-4180

Resources