Special characters not showing right at JSP - spring

I'm using spring MVC, and I've got a problem in a webpage with a table that is showing some records that could have some special characters as Á, ñ, #, #, etc.
In the database they are stored ok. While debugging, it's taken them right from database. But when showing them at the JSP, it's replacing the special chars with "?" (question marks).
I can solve this issue with the following config at my web.xml:
<jsp-config>
<jsp-property-group>
<url-pattern>*.jsp</url-pattern>
<page-encoding>UTF-8</page-encoding>
</jsp-property-group>
</jsp-config>
But when I set this, then there're some problems with functionalities that were working before: the files I upload to my web are not encoded properly, and there are some "hardcoded" properties in my jsps like
<option value="name">Seleccione tipo de ordenación</option>
which are not properly written.
With this jsp-config out then they (this option and the file upload) worked ok.
So, if I set this jsp-config property, then it fails with things that were working before.
Any help? Thanks!

Well, finally, it seems that I'd been fooled :)
I've been told that the name was stored properly into the database. But, actually, it wasn't. The problem was when decoding the file when the user uploads it.
The file itself is a ZIP file which I have to decompress with Apache commons compress. I was opening the file with Cp437, which was working well when the file was created in an english Windows system. However, when creating the file in an spanish Windows system, it failed when opening the file.
Changing the Cp850 charset as the following has solved the problem:
zipFile = new ZipFile(f, "Cp850");

Related

French character é is printing as � in jhipster thymeleaf template

I am using Jhipster application email functionality to send mail on user creation. When sending mail in French the character like é is printing wrongly.
These characters are coming from standard messages_fr.properties file.
Obviously its encoding issue but both in email template html and java code we are setting encoding as UTF-8, which should display this correctly.
While debugging I found that in MailService.java class, content loaded by the SpringTemplateEngine's process method have already loaded the character wrongly before setting the encoding as UTF-8.
My code:
String content = templateEngine.process("activationEmail", context);
Looks like I know the root cause of it but as it is Spring's internal API class, I don't know how to fix this issue.
As Gael pointed I found that the exact root cause of issue is that STS is changing the encoding of .properties files to ISO by default. Changing the file back to UTF-8 is the solution of this issue. Thanks Gael for pointing to this direction.

Populate backend datastore with data using upload script

I am following this tutorial an have a lot of trouble with it as many parts are not explained to beginners: https://cloud.google.com/developers/articles/how-to-build-mobile-app-with-app-engine-backend-tutorial
I came to the part where we need to upload some data to datastore. They are using a .csv file to accomplish that.
This is part of the tutorial where I've stuck:
Create Upload Script
This is the script that actually uploads the simulated information into the backend datastore.
For information about the bulkloader.yaml and more, refer to the App Engine documentation in: Uploading and Downloading Data. Also, you can find the bulkloader.yaml file and the test data here MobileAssistant-Data.
Create a new directory and make it your current directory.
In your editor, create a script file and call it upload_data.sh.
Copy and paste the following code into the file.
#!/bin/sh
appcfg.py upload_data
--config_file bulkloader.yaml --url=http://localhost:8888/remote_api --filename $1 --kind=$2 -e
nobody#nowhere.com
The previous script accepts two arguments separated by a blank space:
./upload_data.sh<data.csv> <class entity name>
The first argument is the name of the csv file that contains the data you want to upload, The second is the name of the entity class to handle the data.
Close and save the file. Notice that the script at this time is intended to be used on local server. It must be modified when the backend application is deployed to the cloud. For example, e-mail “nobody#nowhere.com ” will be changed to an actual e-mail address of the App Engine administrator before deployment.
Places Simulated Data
The simulated data is contained in the file places.csv that you downloaded earlier from the MobileAssistant-Data directory in Mobile Shopping Assistant.
The file contains the following comma separated fields:
name: <place’s name>
placeId: <number that identifies the place>
location: <place’s latitude and longitude coordinates (two values separated by a comma) >
key: <unique key associated with the place>
address: <the place’s address >
Modify Web.xml
To upload data to the datastore, reference the “remote API servlet” and associate it with a URL. You’ll define these mappings in the Web.xml file of the MobileAssistant-Appengine application, as shown next. The web server uses this configuration to identify the servlet to handle a given request.
Note. Notice, you might need to restart Eclipse. if you skip th e Web.xml modification you will get Error 404 Not Found.
<servlet>
<display-name>Remote API Servlet</display-name>
<servlet-name>RemoteApiServlet</servlet-name>
<servlet-class>com.google.apphosting.utils.remoteapi.RemoteApiServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>RemoteApiServlet</servlet-name>
<url-pattern>/remote_api</url-pattern>
</servlet-mapping>
Upload Places Simulated Data
To upload the test data to the data store, run the script that uploads the data from your script directory.
Before you upload your data, make sure to start MobileAssistant-AppEngine as a Web Application (in Debug mode) in Eclipse.
./upload_data.sh <places.csv> Place
At the password request, just press enter.
I don't understand that part with the script. I created a folder age on Desktop, placed inside their files bulkloader.yaml and places.csv. Inside that folder is that upload script.
After I run ./upload_data.sh <places.csv> Place, in my terminal I receive the following error:
upload_data.sh: line 2: appcfg.py: command not found
upload_data.sh: line 3: --config_file: command not found
upload_data.sh: line 4: nobody#nowhere.com: command not found
What should I do to upload that data to Google App Engine datastore? Thank you.
Is appcfg.py in your path, if not then set the path explicitly in your script or add the path the appcfg.py to your PATH

Play! Framework 2.1.3 pdf problems

so I am working on a school project in which we have designed a web application that takes in much user info and creates a pdf then should display that pdf to the user so they can print it off or save it. We are using Play! Framework 2.1.3 as our framework and server and Java for the server side. I create the pdf with Apache's PDFbox library. Every thing works as it should in development mode ie launching it on a localhost with plays run command. the issue is when we put it up to the server and launch with plays start command I it seems to take a snapshot of the directory (or at least the assets/public folder) which is where I am housing the output.pdf file/s (i have attempted to move the file elsewhere but that still seems to result in a 404 error). Initially I believed this to be something with liunx machine we were deploying to which was creating a caching problem and have tried many of the tricks to defeat the browser from caching the pdf
like using javascript to append on a time stamp to the filename,
using this cache-control directive in the play! documentation,
"assets.cache./public/stylesheets/output.pdf"="max-age=0",
then I tried to just save the pdf as a different filename each time and pass back the name of that file and call it directly through the file structure in the HTML
which also works fine with the run command but not the start.
finally I came to the conclusion that when the start command is issued it balls up the files so only the files that are there when the start command is issued can be seen.
I read the documentation here
http://www.playframework.com/documentation/2.1.x/Production
which then I noticed this part
When you run the start command, Play forks a new JVM and runs the
default Netty HTTP server. The standard output stream is redirected to
the Play console, so you can monitor its status.
so it looks like the fact that it forks a new JVM is what is causing my pain.
so my question really is can this be gotten around in some way that a web app can create and display a pdf form? (if I cannot get this to work my only solution
that I can see is that I will have to simulate the form with HTML and fill it out from there) --which I really think is a bad way to do this.
this seems like something that should have a solution but I cannot seem to find or come up with one please help.
i have looked here:
http://www.playframework.com/documentation/2.1.x/JavaStream
the answer may be in there but Im not getting it to work I am pretty novice with this Play! Framework still
You are trying to deliver the generated PDF file to the user by placing it in the assets directory, and putting a link to it in the HTML. This works in development mode because Play finds the assets in the directory. It won't work in production because the project is wrapped up into a jar file when you do play dist, and the contents of the jar file can't be modified by the Play application. (In dev mode, Play has a classpath entry for the directory. In production, the classpath points to the jar file).
You are on the right lines with JavaStream. The way forward is:
Generate the PDF somewhere in your local filesystem (I recommend the temp directory).
Write a new Action in your Application object that opens the file you generated, and serves it instead of a web page.
Check out the Play docs for serving files. This approach also has the advantage that you can specify the filename that the user sees. There is an overloaded function Controller.ok(File file, String filename) for doing this. (When you generate the file, you should give it a unique name, otherwise each request will overwrite the file from a previous request. But you don't want the user to see the unique name).

Concrete5: How to stop macrons disappearing when cache is cleared?

I have a concrete5 site, which uses 'designer content' an add on available via their market place.
Our clients site requires the use of macrons for their language.
Now this is fine throughout 99% of the site, whether hard-coded html or via a content block etc. However, when macrons are used inside a block created with 'designer content' the macron is replaced with a "?"...
Can anyone help?
Unfortunately this site wont let me post an image to help you see whats going on due to my 'low reputation'....riiiiight thats helpful.
Thanks in advance!
usually the apparition of question marks "?" instead of certain characters is the sign of a charset coding problem. With C5 you should be using a generic UTF8 encoding however if your database table was set to use a different charset or if your php settings are set to a different charset, then you will get those weird characters.
You should start with your php.ini and set the charset to utf8
If that doesn't fix the problem, check this thread, it has a useful script to use to fix the database
http://www.concrete5.org/community/forums/usage/utf-8-or-unicode-problems-preventing-corrrupt-fonts-on-the-front/#52300
Be aware however that if content was saved while the charset was not correct, you may discover that the content still looks weird and you will have to insert it again AFTER having set the correct charset.

How to configure jboss rewrite valve settings

I am developing a web app. using struts2 and jboss url rewrite valve as you see from the title. What i want to know is which are the neccessary jboss configuration files to configure rewrite valve settings?
Besides, I couldn't find any information in order to fix my non-english character problem while url rewriting. Some flags like [NE] doesn't help.
Let me clear the case for you;
There is a link on my jsp page, its value is:
http://localhost:8080/struts2Sample/redirectLogin/text/blahblah
And in my rewrite.properties file I added this code;
RewriteCond %{SERVLET_PATH} ^/redirectLogin/text/(.)
RewriteRule ^/redirectLogin/text/(.) /redirectLogin.do?text=$1 [NE,PT,L]
If the 'text' variable include non-english characters like 'şçğüıö' instead of 'blahblah' then the action gets a differently encoded value of 'şçğüıö', I mean it gets a string like '%C4%5F%' or including some another wierd characters.
If you have any idea about how I can fix this issue with, say, a rewriteMap or another flag include a piece of perl code, or (up to me it is more effective solution) configuring a charset or encoding in an xml file of jboss like server.xml etc. I will be glad to hear that.
Thanks a lot,
Baris
I used URLEncoder.encode or decode for UTF-8 in order to prevent character problems

Resources