簡體   English   中英

JSP Scriplet中文字符串比較

[英]JSP Scriplet Chinese String comparison

我正在服務器上嘗試以下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>

當我看到輸出時,它為比較提供了錯誤。

任何人都可以調查一下,並指導我怎么了。

注意:我也嘗試過UTF-8編碼。

謝謝。

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

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

使您將“繁體中文”與“繁體中文[br]”進行比較

s.equalsIgnoreCase(s1)

會給你真實的

@Ritesh:您將s與s1 +“ [br]”進行比較,而應僅將s與s1進行比較。 因此,使用以下代碼:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM