2

Turns out every text I get through an input looses spanish characters like á or ñ and then replaces them with ?.

Inside my HTMLs I always have

<meta charset="UTF-8">

right after I open

<head>

Here's one of my inputs for example:

<div class="col">
  <spring:message code="home.placeholderSearch" var="search"/>    
  <form:input path="search" class="form-control form-control-lg" type="search" id="input_search" placeholder="${search}"/>
  <form:errors path="search" cssClass="error" element="p"/>
</div>

The text diplays with ? when I pass it onto another JSP page and when I upload it to a database it is saved with ? as well.

t.niese
  • 39,256
  • 9
  • 74
  • 101
Flama
  • 772
  • 3
  • 13
  • 39
  • What `content-type` header does jsp send for that page where the form is on? You can check that in the network tab of the developertools in your browser. – t.niese Oct 03 '18 at 18:34

2 Answers2

1

I would suggest that you encode the spanish characters in your text.

Here you find some examples in a list that could help.

https://www.lifewire.com/html-codes-spanish-characters-4062194

There are some options that are well understood by browsers.

&#209; or &Ntilde; or &#xD1; represent for example Capital N-tilde

Capital N-tilde = Ñ

HTH

silverfighter
  • 6,762
  • 10
  • 46
  • 73
  • umm but I'm getting the text from an user input? – Flama Oct 03 '18 at 18:32
  • That just obscures the problem. And won't help for user input. – t.niese Oct 03 '18 at 18:33
  • not nesseserialy: You don't have to do it manually. Use client control that does the translation so users don't have to care. And on the server side use proper escaping utilities https://stackoverflow.com/questions/1265282/recommended-method-for-escaping-html-in-java . It is also for security reason so that nobody could inject script in your text fields. But it's up to you if you want to go the route. – silverfighter Oct 03 '18 at 19:25
0

I always use this code in my HTML files, it has never failed:

<META http-equiv="Content-Type" content="text/html; charset=utf-8" />

I have a Spanish Website: http://SpanishNewsBoard.com

If this isn't working for you, I admit, I have not used "MVC-Spring" and have no idea what it is. What I can add about Spanish, UTF-8, and accent characters is that there are multiple ways that these higher-level ASCII characters are dealt with. The Escaped-HTML character codes work at transmitting HTML-documents with Spanish-Accent characters and (at the same time) avoiding actual UTF-8 (higher than ASCII-Code 255) characters.

In Google Cloud Server, when I use UTF-8 text-files, I have to manually encode the "Charset=UTF-8" into any text-file that contains accented Spanish Characters.

Whatever "JSP Server" you are using (if you can access & control the JSP Host) - if you have written the JSP-File yourself - configure it to associate UTF-8 with the JSP file. I deal with foreign-language I/O everyday, and look for that configuration first. It just depends what server you are using! I use Google.

I don't know if I have helped (not answered the specific question about how to configure a JSP server to associate UTF-8 with a particular JSP-file).... But I have tried to help.

Here is a "screen capture" of my Google Cloud Server account that shows how to manually configure a file to utilize UTF-8 "higher order" ASCII characters:

enter image description here