「JSTL」リスト、配列と文字列のサイズを取得するサンプル
書式
${ fn:length (文字列名/配列名/リスト名)}
使用例
<%@ 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>