在我的jsp页面中,我有这段代码:
circleImageView.setImageDrawable(new ColorDrawable(randomColor));
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
这里有我们的名字:فهد,这就是我想要的。
但是在java类中,当我尝试显示我得到的名称时: UUO 在java中:
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
// ... css + js
</head>
<body>
<% request.setCharacterEncoding("UTF-8");
response.setCharacterEncoding("UTF-8");%>
<form action="AddPerson" name="addPerson"
accept-charset="UTF-8" method="post">
...
</form>
</body>
我不知道为什么,有什么建议吗?
答案 0 :(得分:1)
我找到的解决方案是在web.xml中添加过滤器
<filter>
<filter-name>encodingFilter</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>encodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>