| <!doctype html public "-//w3c//dtd
html 4.0 transitional//en"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=shift_jis"> <title>タグを動的にループさせよう!</title></head> <body text="#000000" bgcolor="#FFFFFF" link="#0000FF" vlink="#800080" alink="#800080"> <div align="center"> <table width="100%" border="0"> <tr> <td bgcolor="0099FF"> <table width="100%" border="0"> <tr> <td height="2" colspan="3"> </td> </tr> <tr> <td height="2" bgcolor="#FFFF66">タイトル</td> <td height="2" bgcolor="#FFFF66">ジャンプ</td> <td height="2" bgcolor="#FFFF66">内容</td> </tr> <tr name="loop"> <td width="50%" height="4" bgcolor="#00FFCC"><!-- @quark id="name" --><!-- /@quark --></td> <td width="8%" height="4" bgcolor="#CCFFFF"><a href="" target="_blank">START</a></td> <td width="42%" height="4" bgcolor="#CCFFFF"><!-- @quark id="set" --><!-- /@quark --></td> </tr> </table> </td> </tr> </table> </div> </body> </html> |
//Kuro API
import jp.kuro.meteor.*;
import jp.kuro.meteor.hook.Looper;
//標準API
import java.util.*;
public class LoopML extends Looper {
Element tag;
Element tag2;
Element tag3;
public void init(Element xt) {
//タグ検索
tag = xt.child("a");
tag2 = xt.cxTag("name");
tag3 = xt.cxTag("set");
}
public void execute(Element elm, Object obj) {
//表示データの加工
HashMap rec = (HashMap) obj;
String NAME = (String) rec.get("name");
String SET = (String) rec.get("set");
if (SET.equals("")) {
SET = " ";
}
String URL = (String) rec.get("url");
//表示ロジック
tag2.clone().content(NAME);
tag.clone().attribute("href", URL);
tag3.clone().content(SET);
}
} |
//標準API
import java.io.*;
import java.util.*;
//ServletAPI
import javax.servlet.*;
import javax.servlet.http.*;
//Kuro API
import jp.kuro.meteor.*;
import jp.kuro.meteor.printer.HttpPrinter;
public class LoopServletHTML extends HttpServlet {
ParserFactory pf;
public void init(ServletConfig sConf) throws ServletException {
//"loop.html"の絶対パスを取得する
ServletContext sc = sConf.getServletContext();
String path = sc.getRealPath("/WEB-INF/html/");
//パーサファクトリオブジェクトを生成し、"loop.html"を読み込む
pf = new ParserFactory(path);
pf.parser(Parser.HTML, "loop.html", "Shift_JIS");
}
public void doGet(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException {
doPost(req, res);
}
public void doPost(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException {
//Parserオブジェクトのコピーを取得する
Parser xt = pf.parser("loop");
//表示用データのセット
ArrayList |
| <html> <head> <title>タグを動的にループさせよう!</title> <meta http-equiv="Content-Type" content="text/html; charset=Shift_JIS"> </head> <body bgcolor="#FFFFFF" text="#000000"> |
import jp.kuro.meteor.*;
import jp.kuro.meteor.hook.Hooker;
public class LoopML2 extends Hooker {
public void execute(Element xt) {
for (int j = 0; j < 3; j++) {
xt.attribute("value", Integer.toString(j));
xt.content("test" + Integer.toString(j));
xt.flush();
}
}
} |
//標準API
import java.io.*;
//ServletAPI
import javax.servlet.*;
import javax.servlet.http.*;
//Kuro API
import jp.kuro.meteor.*;
import jp.kuro.meteor.printer.HttpPrinter;
public class LoopServletHTML2 extends HttpServlet {
ParserFactory pf;
String path2;
//Analyzer anl;
public void init(ServletConfig sConf) throws ServletException {
ServletContext sc = sConf.getServletContext();
//anl = new Analyzer();
String path = sc.getRealPath("/WEB-INF/html/");
path2 = sc.getRealPath("/WEB-INF/");
//パーサファクトリオブジェクトを生成し、"loop2.html"を読み込む
pf = new ParserFactory(path);
pf.parser(Parser.HTML, "loop2.html", "Shift_JIS");
}
public void doGet(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException {
doPost(req, res);
}
public void doPost(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException {
//Parserオブジェクトを取得する
Parser xt = pf.parser("loop2");
//anl.setCharacterEncoding("Shift_JIS");
//req.setCharacterEncoding("Shift_JIS");
//System.out.println(anl.analyze(req));
//System.out.println(req.getParameter("textfield"));
//System.out.println(req.getParameter("textfield2"));
//System.out.println(req.getParameter("submit"));
Element tag = xt.element("option", "value", "test");
tag.execute(new LoopML2());
//反映する
xt.flush();
HttpPrinter prt = new HttpPrinter(res);
prt.print(xt);
}
} |