「7.4 関数を使用するELコード」の版間の差分
ナビゲーションに移動
検索に移動
(ページの作成:「==ある状況において、関数を使用するELコード、EL関数のためのコード、タグライブラリ記述子にEL関数を設定するコードを書く…」) |
|||
23行目: | 23行目: | ||
=====TLD(タグライブラリディスクリプタ)を作成する===== | =====TLD(タグライブラリディスクリプタ)を作成する===== | ||
− | [http://java.sun.com/xml/ns/j2ee/web-jsptaglibrary_2_0.xsd web-jsptaglibrary_2_0.xsd] | + | [[http://java.sun.com/xml/ns/j2ee/web-jsptaglibrary_2_0.xsd web-jsptaglibrary_2_0.xsd]] |
sec7_4.tld | sec7_4.tld | ||
− | + | <taglib xmlns="http://java.sun.com/xml/ns/j2ee" | |
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee | xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee | ||
http://java.sun.com/xml/ns/j2ee/web-jsptaglibrary_2_0.xsd" | http://java.sun.com/xml/ns/j2ee/web-jsptaglibrary_2_0.xsd" | ||
− | version="2.0" | + | version="2.0"> |
− | + | <tlib-version>1.0</tlib-version> | |
− | + | <short-name>sec74util</short-name> | |
− | + | <function> | |
− | + | <name>encurl</name> | |
− | + | <function-class>function.Section7_4_Util</function-class> | |
− | + | <function-signature> | |
java.lang.String encodeUrl(java.lang.String) | java.lang.String encodeUrl(java.lang.String) | ||
− | + | </function-signature> | |
− | + | </function> | |
− | + | <function> | |
− | + | <name>decurl</name> | |
− | + | <function-class>function.Section7_4_Util</function-class> | |
− | + | <function-signature> | |
java.lang.String decodeUrl(java.lang.String) | java.lang.String decodeUrl(java.lang.String) | ||
− | + | </function-signature> | |
− | + | </function> | |
− | + | </taglib> | |
=====web.xml(配備記述子)にtaglib要素を追加===== | =====web.xml(配備記述子)にtaglib要素を追加===== | ||
− | + | <web-app> | |
: | : | ||
− | + | <jsp-config> | |
− | + | <taglib> | |
− | + | <taglib-uri> | |
http://function/sec74util | http://function/sec74util | ||
− | + | </taglib-uri> | |
− | + | <taglib-location> | |
/WEB-INF/sec7_4.tld | /WEB-INF/sec7_4.tld | ||
− | + | </taglib-location> | |
− | + | </taglib> | |
− | + | </jsp-config> | |
: | : | ||
− | + | </web-app> | |
=====JSPから利用する===== | =====JSPから利用する===== | ||
− | + | <%@ page language="java" %> | |
− | + | <%@ page pageEncoding="Shift_JIS" %> | |
− | + | <%@ page contentType="text/html;charset=Shift_JIS"%> | |
− | + | <%@ taglib prefix="utl" uri="http://function/sec74util"%> | |
− | + | <% | |
request.setCharacterEncoding("Shift_JIS"); | request.setCharacterEncoding("Shift_JIS"); | ||
− | % | + | %> |
− | + | <html> | |
− | + | <head> | |
− | + | <meta http-equiv="Content-Type" content="text/html; charset=Shift_JIS"> | |
− | + | <script> | |
− | + | </script> | |
− | + | <title>Section7.4</title> | |
− | + | </head> | |
− | + | <body> | |
− | + | <form name="formSec7_4_1" action="/scwcd/jsp/Section7_4.jsp" method="POST"> | |
− | + | <input type="text" name="url" size="40" value="${param.url}"/><input type="submit" value="encode"/> | |
− | + | <span style="border: 1px groove gray;">${utl:encurl(param.url)}</span> | |
− | + | </form> | |
− | + | <form name="formSec7_4_2" action="/scwcd/jsp/Section7_4.jsp" method="POST"> | |
− | + | <input type="text" name="url2" size="40" value="${param.url2}"/><input type="submit" value="decode"/> | |
− | + | <span style="border: 1px groove gray;">${utl:decurl(param.url2)}</span> | |
− | + | </form> | |
− | + | </body> | |
− | + | </html> | |
---- | ---- | ||
{{amazon|1932394389}} | {{amazon|1932394389}} | ||
− | [http://www.amazon.co.jp/dp/1932394389?tag=typea09-22&link_code=as3&creativeASIN=1932394389&creative=3999&camp=767 SCWCD Exam Study Kit: Java Web Component Developer Certification (ペーパーバック)] | + | [[http://www.amazon.co.jp/dp/1932394389?tag=typea09-22&link_code=as3&creativeASIN=1932394389&creative=3999&camp=767 SCWCD Exam Study Kit: Java Web Component Developer Certification (ペーパーバック)]] |
---- | ---- | ||
{{include_html banner_html, "!J2EE"}} | {{include_html banner_html, "!J2EE"}} |
2020年2月15日 (土) 08:00時点における版
目次
ある状況において、関数を使用するELコード、EL関数のためのコード、タグライブラリ記述子にEL関数を設定するコードを書く
static メソッドを作成する
JSPから直接呼ばれる メソッドクラス(*.java)を作成する
public class Section7_4_Util { public static String encodeUrl(String url) { String result = ""; try { result = URLEncoder.encode(url, "UTF-8"); } catch (UnsupportedEncodingException e) {} return result; } public static String decodeUrl(String url) { String result = ""; try { result = URLDecoder.decode(url, "UTF-8"); } catch (UnsupportedEncodingException e) {} return result; } }
TLD(タグライブラリディスクリプタ)を作成する
sec7_4.tld
<taglib xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-jsptaglibrary_2_0.xsd" version="2.0"> <tlib-version>1.0</tlib-version> <short-name>sec74util</short-name> <function> <name>encurl</name> <function-class>function.Section7_4_Util</function-class> <function-signature> java.lang.String encodeUrl(java.lang.String) </function-signature> </function> <function> <name>decurl</name> <function-class>function.Section7_4_Util</function-class> <function-signature> java.lang.String decodeUrl(java.lang.String) </function-signature> </function> </taglib>
web.xml(配備記述子)にtaglib要素を追加
<web-app> : <jsp-config> <taglib> <taglib-uri> http://function/sec74util </taglib-uri> <taglib-location> /WEB-INF/sec7_4.tld </taglib-location> </taglib> </jsp-config> : </web-app>
JSPから利用する
<%@ page language="java" %> <%@ page pageEncoding="Shift_JIS" %> <%@ page contentType="text/html;charset=Shift_JIS"%> <%@ taglib prefix="utl" uri="http://function/sec74util"%> <% request.setCharacterEncoding("Shift_JIS"); %> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=Shift_JIS"> <script> </script> <title>Section7.4</title> </head> <body> <form name="formSec7_4_1" action="/scwcd/jsp/Section7_4.jsp" method="POST"> <input type="text" name="url" size="40" value="${param.url}"/><input type="submit" value="encode"/> <span style="border: 1px groove gray;">${utl:encurl(param.url)}</span> </form> <form name="formSec7_4_2" action="/scwcd/jsp/Section7_4.jsp" method="POST"> <input type="text" name="url2" size="40" value="${param.url2}"/><input type="submit" value="decode"/> <span style="border: 1px groove gray;">${utl:decurl(param.url2)}</span> </form> </body> </html>
[SCWCD Exam Study Kit: Java Web Component Developer Certification (ペーパーバック)]
© 2006 矢木浩人