jsp中重音字符的问题 [英] Problems with accented characters in jsp

查看:147
本文介绍了jsp中重音字符的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在表单上收集重音字符[áéíóúÁÉÍÓÚ],但未正确发送到:

I am trying to collect accented characters [áéíóúÁÉÍÓÚ] on a form but are not correctly sent to action:

JSP:

<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
[. . .]
<s:form action="resultRot" method="post" theme="simple">
<s:textfield name="param" theme="simple" size="20" maxlength="20" style="text-transform: uppercase; text-align:center"/>
<s:submit name="submit" key="ejercicios.roturaPalabras.corregir" align="center"/>

当我在动作类中选择参数param时,它不包含正确的值。
我使用Eclipse和我签出的项目编码是ISO-8859-1

When I pick the parameter param in the action class, it does not contain the correct values. I use Eclipse and I checked out the project encoding is ISO-8859-1

我也尝试使用UTF-8编码(在我的jsp) :

I´ve tried with UTF-8 encoding too (in my jsp):

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>

我也尝试过使用URLDecoder / Encoder:

I´ve tried with URLDecoder/Encoder too:

String prueba = java.net.URLDecoder.decode(solucionIntroducida, "ISO-8859-1"); 

提前感谢

推荐答案

最佳做法是使用 UTF-8 无处不在。

The best practice is to use UTF-8 everywhere.

在这里,您可以通过更改应用程序服务器的连接器来了解如何进行操作,而对于其他部分,您可以在每个 JSP (像你在做),或者在 web.xml 中指定一次:

Here you can find how to do it by altering the application server's connectors, while for the other parts you can simply specify it in each JSP (like you are doing), or specify it once in web.xml:

<jsp-config>
    <jsp-property-group>
        <url-pattern>*.jsp</url-pattern>
        <page-encoding>UTF-8</page-encoding>
    </jsp-property-group>
</jsp-config>

调试(和打印)请求 Eclipse 中,您需要确保使用 UTF-8 作为文本文件编码

To debug (and print) a Request in Eclipse, you need to ensure that you are using UTF-8 as text file encoding.

转到首选项 - > 常规 - > 工作区 - > 文本文件编码,并设置其他:UTF-8

Go to Preferences -> General -> Workspace -> Text file encoding , and set Other: UTF-8

在代码中,一定要始终指定字符将字符串转换为字节[]或反之亦然:

In the code, be sure to always specify the character encoding when converting String to Byte[] or viceversa:

String str = new String(myByteArray,"UTF-8");

byte[] ba = myString.toByteArray("UTF-8");

这是为了在任何地方保留正确的字符所需的步骤。

This are the steps needed in order to preserve the correct characters everywhere.

这篇关于jsp中重音字符的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆