「JSTL」リスト、配列と文字列のサイズを取得するサンプル

2021年5月11日

書式
${ fn:length (文字列名/配列名/リスト名)}
使用例

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<%@ page language="java" contentType="text/html;charset=Windows-31J"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<html><body>
<%
/*文字列*/
String strA = "this is a message";
pageContext.setAttribute("resA",strA);
/*配列*/
String[] strB = {"A001","B002","C003"};
pageContext.setAttribute("resB",strB);
/*リスト*/
java.util.List cftC = new java.util.ArrayList();
cftC.add("111");
cftC.add("222");
cftC.add("333");
pageContext.setAttribute("resC",cftC);
%>
${ fn:length( resA ) }  
${ fn:length( resB ) } 
${ fn:length( resC ) } 
</body></html>
<%@ page language="java" contentType="text/html;charset=Windows-31J"%> <%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%> <html><body> <% /*文字列*/ String strA = "this is a message"; pageContext.setAttribute("resA",strA); /*配列*/ String[] strB = {"A001","B002","C003"}; pageContext.setAttribute("resB",strB); /*リスト*/ java.util.List cftC = new java.util.ArrayList(); cftC.add("111"); cftC.add("222"); cftC.add("333"); pageContext.setAttribute("resC",cftC); %> ${ fn:length( resA ) }   ${ fn:length( resB ) }  ${ fn:length( resC ) }  </body></html>
<%@ page language="java" contentType="text/html;charset=Windows-31J"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>

<html><body>

<%
/*文字列*/
String strA = "this is a message";
pageContext.setAttribute("resA",strA);

/*配列*/
String[] strB = {"A001","B002","C003"};
pageContext.setAttribute("resB",strB);

/*リスト*/
java.util.List cftC = new java.util.ArrayList();
cftC.add("111");
cftC.add("222");
cftC.add("333");
pageContext.setAttribute("resC",cftC);
%>

${ fn:length( resA ) }  
${ fn:length( resB ) } 
${ fn:length( resC ) } 

</body></html>

 

JSTL

Posted by arkgame