我正在服务器上尝试以下 JSP 代码
<%@ page language="java" contentType="text/html; charset=UTF-16"
pageEncoding="UTF-16"%>
<!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-16">
<title>Insert title here</title>
</head>
<body>
<%
String s = "繁體中文";
String s1 = "繁體中文";
out.println(s + "<br/>");
out.println(s1 + "<br/>");
out.println(s.equalsIgnoreCase(s1 + "<br/>"));
%>
</body>
</html>
当我看到输出时,它给出了 false 进行比较。
任何人都可以调查一下并指导我出了什么问题吗?
注意:我也尝试过UTF-8编码。
谢谢。
最佳答案
因为你比较“繁体中文”和“繁体中文[br]”
s.equalsIgnoreCase(s1)
会给你真实
关于java - JSP Scriptlet中文字符串比较,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22039458/