【发布时间】:2016-02-29 17:35:38
【问题描述】:
我已经访问了有关 HTML 中的 UTF-8 编码的每一个问题,但似乎没有任何事情可以让它像预期的那样工作。
我添加了meta 标签:没有任何改变。
我在form 中添加了accept-charset 属性:没有任何改变。
JSP 文件
<%@ page pageEncoding="UTF-8" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<title>Editer les sous-titres</title>
</head>
<body>
<form method="post" action="/Subtitlor/edit" accept-charset="UTF-8">
<h3 name="nameOfFile"><c:out value="${ nameOfFile }"/></h3>
<input type="hidden" name="nameOfFile" id="nameOfFile" value="${ nameOfFile }"/>
<c:if test="${ !saved }">
<input value ="Enregistrer le travail" type="submit" style="position:fixed; top: 10px; right: 10px;" />
</c:if>
<a href="/Subtitlor/" style="position:fixed; top: 50px; right: 10px;">Retour à la page d'accueil</a>
<c:if test="${ saved }">
<div style="position:fixed; top: 90px; right: 10px;">
<c:out value="Travail enregistré dans la base de donnée"/>
</div>
</c:if>
<table border="1">
<c:if test="${ !saved }">
<thead>
<th style="weight:bold">Original Line</th>
<th style="weight:bold">Translation</th>
<th style="weight:bold">Already translated</th>
</thead>
</c:if>
<c:forEach items="${ subtitles }" var="line" varStatus="status">
<tr>
<td style="text-align:right;"><c:out value="${ line }" /></td>
<td><input type="text" name="line${ status.index }" id="line${ status.index }" size="35" /></td>
<td style="text-align:right"><c:out value="${ lines[status.index].content }"/></td>
</tr>
</c:forEach>
</table>
</form>
</body>
</html>
小服务程序
for (int i = 0 ; i < 2; i++){
System.out.println(request.getParameter("line"+i));
}
输出
Et ton père et sa soeur
Il ne sera jamais parti.
【问题讨论】:
-
@SubOptimal 非常感谢,这行得通。但这会稍微减慢应用程序的速度,因为我的表单中有近 1000 个输入。您是否知道另一种方法可以做到这一点?
-
你试过了吗?这就是 Rails 所做的:stackoverflow.com/questions/27338154/…
-
@JacobWalker 因为我使用的是 POST,所以我认为它不起作用。