string 比较 EL 中的字符串

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8355675/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 01:18:20  来源:igfitidea点击:

Comparing strings in EL

stringjspcompareel

提问by tschaei

I'm giving a User object to JSP and want to compare an attribute of the user with a given String. What I'm doing right now is the following:

我向 JSP 提供了一个 User 对象,并希望将用户的属性与给定的字符串进行比较。我现在正在做的是以下内容:

<input type="radio" name="lang" value="ger" <c:if test="${user.comLanguage.equals("ger")}">checked="yes"</c:if>/>German</br>

But all I get is the following Exception:

但我得到的只是以下异常:

org.apache.jasper.JasperException: /WEB-INF/jsp/library/home.jsp (line: 22, column: 95) equal symbol expected

where column 95 is one of the letters of comLanguage.

其中第 95 列是 的字母之一comLanguage

What's the correct syntax here?

这里的正确语法是什么?

回答by StKiller

Try this :

尝试这个 :

<c:if test="${user.comLanguage=='ger'}">

Also you can try ternary if:

您也可以在以下情况下尝试三元:

${user.comLanguage=='ger' ? 'checked' : ''}