Problem showing special characters JAVA-Kdb

0

I extract the data from a DB through a connector, but when it comes to showing them in a list in a jsp, it shows them to me like this:

How can I format the Strings when I take them out or what can I do to show them with their accents and the ñ ??

Thank you.

With this code I extract:

con = new c(HOST, PORT, USER_PASS);

        rs = (c.Flip) con.k(query);

        for(int fila = 1; fila < con.n(rs.y[0]); fila++){
            for(int col = 0; col < rs.x.length; col++){
                if(con.at(rs.y[col], fila)!=null){       
                   dataStr = con.at(rs.y[col], fila).toString(); 

                }

                if(dataStr!=null){
                    if(!dataStr.matches(".*\d+.*")){
                        muni.setName(dataStr);                            
                    } else if (!dataStr.contains("-")){
                        muni.setNhab(dataStr);
                        data = data + Integer.valueOf(dataStr);
                        if(selectedMuni.contains(muni.getName())){
                            muni.setBool("true");
                        } else {
                            muni.setBool("false");
                        }
                    } 

                }  
            }
            result.add(muni);

With this code I show:

<%@page contentType="text/html" pageEncoding="UTF-8"%>    
<c:forEach var="municipio" items="${requestScope.municipios}">
<option value="${municipio.name}" <c:if test="${municipio.bool eq 'true'}">selected</c:if>>${municipio.name}</option>'<c:forEach var="municipio" items="${requestScope.municipios}">
    
asked by ZiPoTaTo 24.01.2018 в 12:27
source

2 answers

0

Apparently, your way of presenting data should be JSPs.

Therefore, you should tell your pages that you are coding them as UTF-16.

As they say in this answer so that the JSP pages appear with that coding, you must add them:

<%@ page contentType="text/html; charset=UTF-16" %>

On the other hand, you must also configure your database with the same encoding to avoid problems.

    
answered by 24.01.2018 в 13:04
0

It depends a lot on the database management system (MySQL, Oracle, PosttegreSQL, to name a few) that you are using and how you have defined the field you are consulting.

In principle Java has no problem representing in tildes and ñ s because the String class works with a UTF-16 encoding as it says in the Java 7 API :

  

A String represents a string in the UTF-16 format in which   supplementary characters are represented by surrogate pairs (see the   Unicode Character Representations in the Character class for   more information). Index values refer to char code units, so a   supplementary character uses two positions in a String.

But to make it look better the problem would be good to share the code where you query the database and where you sample.

To solve this type of errors I find interesting the method proposed in this answer , even if it is PHP and I do not think Java can extract the most important ideas.

    
answered by 24.01.2018 в 12:53