Java 无法在jsp上显示希伯来文字符
我在jsp上显示UTF-8字符时遇到问题 我在eclipse中使用eclipse、jsp文件、java类和Tomcat7内置。 我有3个文件:Java 无法在jsp上显示希伯来文字符,java,eclipse,jsp,tomcat,Java,Eclipse,Jsp,Tomcat,我在jsp上显示UTF-8字符时遇到问题 我在eclipse中使用eclipse、jsp文件、java类和Tomcat7内置。 我有3个文件: - index.jsp <%@ page language="java" contentType="text/html; charset=UTF-8"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org
- index.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<form action="getProperties.jsp" method="post" name="GettingMovieParameters">
Choose your name : <input type="text" name="hebrewMovieName">
<input type="submit" value="send">
</form>
</body>
</html>
-index.jsp
在此处插入标题
选择您的姓名:
- getProperties.jsp
在此处插入标题
电影的希伯来语名称是:
UserData.java
公共类用户数据{
私有字符串hebrewMovieName;
公共字符串getHebrewMovieName(){
返回hebrewMovieName;
}
公共void setHebrewMovieName(字符串hebrewMovieName){
System.out.println(“设置:“+hebrewMovieName”);
this.hebrewMovieName=hebrewMovieName;
}
}
我尝试在eclipse编辑器、jsp文件、html文件等中设置UTF-8编码。
什么都不管用。
我不知道我错过了什么,但如果有人能帮助我,我会很高兴的。。
谢谢
或者。您似乎需要配置webapp以正确设置传入post数据的字符编码。不幸的是,这里的默认值是ISO-8859-1,tomcat坚持规范中设置的默认值。您需要手动将其设置为UTF-8。这里解释如下: 简短版本:将其添加到
web.xml
应有助于:
字符编码滤波器
org.apache.catalina.filters.SetCharacterEncodingFilter
编码
UTF-8
字符编码滤波器
/*
您似乎需要配置webapp以正确设置传入post数据的字符编码。不幸的是,这里的默认值是ISO-8859-1,tomcat坚持规范中设置的默认值。您需要手动将其设置为UTF-8。这里解释如下:
简短版本:将其添加到web.xml
应有助于:
字符编码滤波器
org.apache.catalina.filters.SetCharacterEncodingFilter
编码
UTF-8
字符编码滤波器
/*
服务器端
过滤器可能是解决方案,我使用了Spring的CharacterEncodingFilter:
<filter>
<filter-name>CharacterEncodingFilter</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
<init-param>
<param-name>forceEncoding</param-name>
<param-value>true</param-value>
</init-param>
</filter>
...
<filter-mapping>
<filter-name>CharacterEncodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
字符编码滤波器
org.springframework.web.filter.CharacterEncodingFilter
编码
UTF-8
强制编码
真的
...
字符编码滤波器
/*
客户端
如果在显示或发送字符时遇到问题,请尝试使用jsp页面指令设置页面编码:
<jsp:directive.page contentType="text/html;charset=UTF-8"/>
(应同时更换和标签)服务器端
过滤器可能是解决方案,我使用了Spring的CharacterEncodingFilter:
<filter>
<filter-name>CharacterEncodingFilter</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
<init-param>
<param-name>forceEncoding</param-name>
<param-value>true</param-value>
</init-param>
</filter>
...
<filter-mapping>
<filter-name>CharacterEncodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
字符编码滤波器
org.springframework.web.filter.CharacterEncodingFilter
编码
UTF-8
强制编码
真的
...
字符编码滤波器
/*
客户端
如果在显示或发送字符时遇到问题,请尝试使用jsp页面指令设置页面编码:
<jsp:directive.page contentType="text/html;charset=UTF-8"/>
(应同时替换和标记)确保浏览器未缓存页面。最好清除浏览器中的缓存、cookies等,然后重试。我只是用新浏览器测试它,然后清除缓存。。但是。。它不起作用。仅用于测试,如果您在
中将method=“post”
更改为method=“get”
,与get相同的结果,是否会有所帮助。。仍然无法看到字符。在何处显示问题?到浏览器?在编辑部?取而代之的是什么?确保您的浏览器没有缓存页面。最好清除浏览器中的缓存、cookies等,然后重试。我只是用新浏览器测试它,然后清除缓存。。但是。。它不起作用。仅用于测试,如果您在中将method=“post”
更改为method=“get”
,与get相同的结果,是否会有所帮助。。仍然无法看到字符。在何处显示问题?到浏览器?在编辑部?我试过了,但没有成功。我正在使用Tomcat7,我做到了。。但我仍然有同样的问题。我的答案只适用于post请求;我希望我没有把这件事搞砸,因为我问过它是否适用于发表评论。对于get请求,可以在server.xml
中进行不同的配置调整,方法是将URIEncoding=“UTF-8”
添加到解决方案工作的get请求中!非常感谢!!你对这篇文章还有别的想法吗?我完全糊涂了。过滤器应仅适用于post请求,而URIEncoding=“UTF-8”
仅适用于get请求。因此,添加过滤器然后开始工作是我无法解释的。不。。我尝试将URIEncoding=“UTF-8”与get请求一起使用,结果成功了。过滤器不适用于我的post请求。。你有什么办法解决post问题吗?我试过了,但没有成功。我正在使用Tomcat7,我做到了。。但我仍然有同样的问题。我的答案只适用于post请求;我希望我没有把这件事搞砸,因为我问过它是否适用于发表评论。对于get请求,可以在server.xml
中进行不同的配置调整,方法是将URIEncoding=“UTF-8”
添加到解决方案工作的get请求中!非常感谢!!你对这篇文章还有别的想法吗?我完全糊涂了。过滤器应仅适用于post请求,而URIEncoding=“UTF-8”
仅适用于get请求。因此,添加过滤器然后开始工作是我无法解释的。不。。我尝试将URIEncoding=“UTF-8”与get请求一起使用,结果成功了。过滤器不适用于我的post请求。。你有什么办法解决post问题吗?