简体   繁体   English

JSP Scriplet中文字符串比较

[英]JSP Scriplet Chinese String comparison

I am trying the following JSP code on server 我正在服务器上尝试以下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>

and when I see the output, it gives me false for comparison. 当我看到输出时,它为比较提供了错误。

Could anyone please look into this and guide me whats wrong. 任何人都可以调查一下,并指导我怎么了。

Note: I have tried UTF-8 encoding as well. 注意:我也尝试过UTF-8编码。

Thanks. 谢谢。

您可能需要如下更改条件。

out.println(s.equalsIgnoreCase(s1));

cause you comparing "繁體中文" with "繁體中文[br]" 使您将“繁体中文”与“繁体中文[br]”进行比较

s.equalsIgnoreCase(s1)

will give you true 会给你真实的

@Ritesh: You are comparing s with s1+"[br]" while you should compare s with s1 only. @Ritesh:您将s与s1 +“ [br]”进行比较,而应仅将s与s1进行比较。 So use the following code: 因此,使用以下代码:

out.println(s.equalsIgnoreCase(s1));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM