Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jsp/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
String 如何比较Jsp中的两个字符串?_String_Jsp_Substring - Fatal编程技术网

String 如何比较Jsp中的两个字符串?

String 如何比较Jsp中的两个字符串?,string,jsp,substring,String,Jsp,Substring,但是count1始终返回0您可以使用“==”符号来比较JSP中的两个字符串,我会在它们之间放置空格,并将双引号更改为单引号,例如: if(student_code.substring(0,3 )=="MLV") count1++; 希望这能有所帮助 参考职位: 这看起来不像JSP代码。它看起来更像是JSP中的一个脚本,而JSP只是java代码。如果是这种情况,您仍然需要使用equals进行字符串比较,如 if(student_code.substring(0,3 )=="MLV") c

但是
count1
始终返回0

您可以使用“==”符号来比较JSP中的两个字符串,我会在它们之间放置空格,并将双引号更改为单引号,例如:

if(student_code.substring(0,3 )=="MLV")
  count1++;
希望这能有所帮助

参考职位:

这看起来不像JSP代码。它看起来更像是JSP中的一个脚本,而JSP只是java代码。如果是这种情况,您仍然需要使用
equals
进行字符串比较,如

if(student_code.substring(0,3 )=="MLV")
  count1++;
如果要在JSP中对字符串进行子字符串和比较,请使用JSTL函数,如下所示

if(student_code.substring(0,3 ).equals("MLV"))
      count1++;

同样,要使上述JSTL代码正常工作,您需要在JSP中导入以下标记库

<c:set var="mystring" value="<%=student_code%>"/>

<c:if test="${fn:substring(mystring, 0, 3) == 'MLV'}">
     <%count1++;%>
<c:if>

Oho朋友。。。。我只是把代码改成

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>

…及其工作原理

请阅读本文并理解为什么您的语句
您可以使用“==”符号来比较两个字符串
应附带免责声明。在jsp中是有效的,被翻译为Object.equals()
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>
str1=student_code.substring(0,3 ).trim();
if(str1.equals("YML"))
  count1++;