我在 jsp 上显示 UTF-8 字符时遇到问题。
我在eclipse中使用eclipse、jsp文件、java类和tomcat 7 buit。我有 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/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>
- 获取属性.jsp
<jsp:useBean id="propertiesBean" class="my.movieDownloader.org.UserData" scope="session"/>
<jsp:setProperty name="propertiesBean" property="*"/>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
Movie hebrew name is : <%= propertiesBean.getHebrewMovieName() %>
</body>
</html>
UserData.java
public class UserData {
private String hebrewMovieName;
public String getHebrewMovieName() {
return hebrewMovieName;
}
public void setHebrewMovieName(String hebrewMovieName) {
System.out.println("Setting up: " +hebrewMovieName);
this.hebrewMovieName = hebrewMovieName;
}
}
我尝试在 Eclipse 编辑器、jsp 文件、html 文件等中设置 UTF-8 编码,但没有任何效果。我不知道我错过了什么,但如果有人可以帮助我,我会很高兴.. 谢谢,或者。