{"id":1222,"date":"2018-04-22T09:25:25","date_gmt":"2018-04-22T00:25:25","guid":{"rendered":"http:\/\/www.code-magagine.com\/?p=1222"},"modified":"2023-05-27T20:43:25","modified_gmt":"2023-05-27T11:43:25","slug":"%e3%80%90jsp%e3%80%91jstl%e3%81%a7%e6%9d%a1%e4%bb%b6%e5%88%86%e5%b2%90%e3%82%92%e8%a1%8c%e3%81%86%e3%81%ab%e3%81%af%ef%bc%9f","status":"publish","type":"post","link":"http:\/\/www.code-magagine.com\/?p=1222","title":{"rendered":"\u3010JSP\u3011JSTL\u3067\u6761\u4ef6\u5206\u5c90\u3092\u884c\u3046\u306b\u306f\uff1f"},"content":{"rendered":"<p>JSTL\u3067\u3001\u6761\u4ef6\u5206\u5c90\u3092\u884c\u3046\u3053\u3068\u304c\u3067\u304d\u308b\u30bf\u30b0\u3068\u3057\u3066\u306f\u4e0b\u8a18\u3067\u3059\u3002<\/p>\n<h2>\u6761\u4ef6\u6587\u7528\u306e\u30bf\u30b0<\/h2>\n<table>\n<tbody>\n<tr>\n<th>\u30bf\u30b0<\/th>\n<th>\u8aac\u660e<\/th>\n<\/tr>\n<tr>\n<td>c:if<\/td>\n<td>\u6761\u4ef6\u5206\u5c90<\/td>\n<\/tr>\n<tr>\n<td>c:choose<\/td>\n<td>\u8907\u6570\u306e\u6761\u4ef6\u5206\u5c90<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2>\u3067\u306f\u3001\u5b9f\u969b\u306b\u8a66\u3057\u3066\u898b\u307e\u3057\u3087\u3046\u3002<\/h2>\n<h3>\u30b5\u30f3\u30d7\u30eb\u3067\u4f7f\u7528\u3059\u308bJavaBeans<\/h3>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\r\npackage bean;\r\n\r\npublic class TestBean {\r\n\r\n\tprivate String name;\r\n\r\n\tprivate int age;\r\n\r\n\tpublic String getName() {\r\n\t\treturn name;\r\n\t}\r\n\r\n\tpublic void setName(String name) {\r\n\t\tthis.name = name;\r\n\t}\r\n\r\n\tpublic int getAge() {\r\n\t\treturn age;\r\n\t}\r\n\r\n\tpublic void setAge(int age) {\r\n\t\tthis.age = age;\r\n\t}\r\n\r\n}\r\n<\/pre>\n<h2>c:if\uff08\u5358\u4e00\u306e\u6761\u4ef6\u3068\u3059\u308b\u5834\u5408\u3002\uff09<\/h2>\n<h4>\u30b5\u30f3\u30d7\u30eb<\/h4>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\r\n&lt;%@page contentType=&quot;text\/html; charset=UTF-8&quot; %&gt;\r\n&lt;%@page import=&quot;bean.*&quot; %&gt;\r\n&lt;%@taglib prefix=&quot;c&quot; uri=&quot;http:\/\/java.sun.com\/jsp\/jstl\/core&quot;%&gt;\r\n\r\n&lt;HTML&gt;\r\n&lt;HEAD&gt;\r\n&lt;TITLE&gt;JSTLTest&lt;\/TITLE&gt;\r\n&lt;\/HEAD&gt;\r\n&lt;BODY&gt;\r\n\r\n&lt;% TestBean bean = new TestBean(); bean.setName(&quot;\u592a\u90ce&quot;); bean.setAge(40); request.setAttribute(&quot;bean&quot;,bean); %&gt;\r\n\r\n&lt;c:if test=&quot;${bean.age&gt;=40}&quot;&gt;\r\n${bean.name}\u3055\u3093\u306f\u3001\u3082\u3046\u4e2d\u5e74\u3067\u3059\u2026\u3002\r\n&lt;\/c:if&gt;\r\n\r\n\r\n&lt;\/BODY&gt;\r\n&lt;\/HTML&gt;\r\n<\/pre>\n<h4>\u30dd\u30a4\u30f3\u30c8<\/h4>\n<ul>\n<li>c:if\u306e\u300ctest\u300d\u5c5e\u6027\u306b<strong>EL\u5f0f\u3092\u4f7f\u7528\u3057\u3066\u3044\u307e\u3059\u3002<\/strong>\u30b9\u30b3\u30fc\u30d7\u306b\u683c\u7d0d\u3055\u308c\u305f\u5024\u3092\u4f7f\u7528\u3057\u3066\u6761\u4ef6\u5206\u5c90\u3092\u884c\u308f\u305b\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/li>\n<li>else\u306f\u4f7f\u3048\u306a\u3044\u306e\u3067\u3001\u6ce8\u610f\u3067\u3059\u3002\uff08\u8907\u6570\u6761\u4ef6\u6587\u304c\u3042\u308b\u5834\u5408\u306f\u3001\u300cc:choose\u300d\u3092\u4f7f\u3044\u307e\u3057\u3087\u3046\u3002<\/li>\n<\/ul>\n<h4>\u5b9f\u884c\u7d50\u679c<\/h4>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-1232\" src=\"http:\/\/www.code-magagine.com\/wp-content\/uploads\/2018\/04\/cif\u30b5\u30f3\u30d7\u30eb.png\" alt=\"\" width=\"252\" height=\"55\" \/><\/p>\n<h2>c:choose<\/h2>\n<h3>\u30b5\u30f3\u30d7\u30eb<\/h3>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\r\n&lt;%@page contentType=&quot;text\/html; charset=UTF-8&quot; %&gt;\r\n&lt;%@page import=&quot;bean.*&quot; %&gt;\r\n&lt;%@taglib prefix=&quot;c&quot; uri=&quot;http:\/\/java.sun.com\/jsp\/jstl\/core&quot;%&gt;\r\n\r\n&lt;HTML&gt;\r\n&lt;HEAD&gt;\r\n&lt;TITLE&gt;JSTLTest&lt;\/TITLE&gt;\r\n&lt;\/HEAD&gt;\r\n&lt;BODY&gt;\r\n\r\n&lt;% TestBean bean = new TestBean(); bean.setName(&quot;\u592a\u90ce&quot;); bean.setAge(39); request.setAttribute(&quot;bean&quot;,bean); %&gt;\r\n\r\n&lt;c:choose&gt;\r\n\t&lt;c:when test=&quot;${bean.age&gt;=40}&quot;&gt;\r\n\t\t${bean.name}\u3055\u3093\u306f\u3001\u3082\u3046\u4e2d\u5e74\u3067\u3059\u2026\u3002\r\n\t&lt;\/c:when&gt;\r\n\t&lt;c:otherwise&gt;\r\n\t\t${bean.name}\u3055\u3093\u306f\u3001\u307e\u3060\u82e5\u3044\u3067\u3059\uff01\r\n\t&lt;\/c:otherwise&gt;\r\n&lt;\/c:choose&gt;\r\n\r\n\r\n&lt;\/BODY&gt;\r\n&lt;\/HTML&gt;\r\n<\/pre>\n<h3>\u30dd\u30a4\u30f3\u30c8<\/h3>\n<ul>\n<li>c:if\u3067\u306f\u5b9f\u73fe\u3067\u304d\u306a\u304b\u3063\u305f\u3001else\u3092\u5b9f\u8cea\u7684\u306b\u4f7f\u3046\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002\u8907\u6570\u6761\u4ef6\u304c\u3042\u308b\u5834\u5408\u306f\u3001\u3053\u3061\u3089\u3092\u4f7f\u3044\u307e\u3057\u3087\u3046\uff01<\/li>\n<\/ul>\n<h3>\u5b9f\u884c\u7d50\u679c<\/h3>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-1237\" src=\"http:\/\/www.code-magagine.com\/wp-content\/uploads\/2018\/04\/choose.png\" alt=\"\" width=\"240\" height=\"48\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"JSTL\u3067\u3001\u6761\u4ef6\u5206\u5c90\u3092\u884c\u3046\u3053\u3068\u304c\u3067\u304d\u308b\u30bf\u30b0\u3068\u3057\u3066\u306f\u4e0b\u8a18\u3067\u3059\u3002 \u6761\u4ef6\u6587\u7528\u306e\u30bf\u30b0 \u30bf\u30b0 \u8aac\u660e c:if \u6761\u4ef6\u5206\u5c90 c:choose \u8907\u6570\u306e\u6761\u4ef6\u5206\u5c90 \u3067\u306f\u3001\u5b9f\u969b\u306b\u8a66\u3057\u3066\u898b\u307e\u3057\u3087\u3046\u3002 \u30b5\u30f3\u30d7\u30eb\u3067\u4f7f\u7528\u3059\u308bJavaBeans c:i [&hellip;]","protected":false},"author":1,"featured_media":1399,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[5],"tags":[],"_links":{"self":[{"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/posts\/1222"}],"collection":[{"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1222"}],"version-history":[{"count":11,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/posts\/1222\/revisions"}],"predecessor-version":[{"id":20252,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/posts\/1222\/revisions\/20252"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/media\/1399"}],"wp:attachment":[{"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1222"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1222"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1222"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}