Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jsp/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
.properties或JSP的编码有问题_Jsp_Encoding_Utf 8_Internationalization_Properties - Fatal编程技术网

.properties或JSP的编码有问题

.properties或JSP的编码有问题,jsp,encoding,utf-8,internationalization,properties,Jsp,Encoding,Utf 8,Internationalization,Properties,我有一个jsp文件: <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%> <%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>

我有一个jsp文件:

   <%@ page language="java" contentType="text/html;
charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<c:set var="language"
    value="${not empty param.language ? param.language : not empty language ? language : pageContext.request.locale}"
    scope="session" />
<fmt:setLocale value="${language}" />
<fmt:setBundle basename="localization.text" />
<!DOCTYPE html>
<html lang="${language}">
<head>
<title>JSP/JSTL i18n demo</title>
</head>
<body>
<form accept-charset="UTF-8"><select id="language"
    name="language" onchange="submit()">
    <option value="en" ${language=='en' ? 'selected' : ''}>English</option>
    <option value="ru" ${language=='ru' ? 'selected' : ''}>Russian</option>
</select></form>
<form name="loginForm" method="POST" action="controller"><input
    type="hidden" name="command" value="login" /> <label for="login"><fmt:message
    key="login.label.login" />:</label> <input type="text" name="login" value="">
<br>
<input type="hidden" name="command" value="password" /> <label
    for="password"><fmt:message key="login.label.password" />:</label> <input
    type="password" name="password" value=""> <br>
<fmt:message key="login.button.submit" var="buttonValue" /> <input
    type="submit" name="submit" value="${buttonValue}"></form>
</body>
</html>
顺便说一句,这是英文文件:

login.label.login = Login
login.label.password = Password
login.button.submit = Sign in
但浏览器给了我这样的东西:

我将.properties文件保存在utf-8中,并在两个程序(第一个是Eclipse,第二个是Notepad++)的帮助下进行了尝试,但我真的不知道如何处理这个编码问题


非常感谢您的帮助。

不幸的是,当通过
资源包
读取
.properties
文件时,它总是期望ISO-8859-1

通常的方法是对属性文件中的非ascii字符进行unicode转义。然后它会像这样:

小时数标签=\u0427\u0430\u0441\u043e\u0432\u0435

是一个eclipse插件,它使开发过程中的逃逸变得容易

另一种更繁琐的方法是提供您自己的标记,该标记使用您自己的
ResourceBundle
实现,而该实现反过来使用
.load(reader)
,其中
reader
使用
UTF-8

login.label.login = Login
login.label.password = Password
login.button.submit = Sign in